Sunday, July 03, 2016

Image classification with TensorFlow

Lately I am spending time experimenting with scikit-learn and TensorFlow (Google) open source library for Machine Learning.

Using image recognition library from TensorFlow, I hacked together a web service with an end point where I can send an image and get back with prediction for the content of the image.
To consume the API, initially I thought of making an Android app, later it made sense to follow up on my previous post and use a chat bot. My experimental project was simple, I should be able to send an image to my chat-bot in WhatsApp, and get back the prediction.

Tensorflow is easy to learn and use and it has decent documentation. I trained the model using sample image database downloaded from google example. To create the web endpoint, I used flask, a python web framework.
Now I can test, my web service by uploading my test image

Prediction :
    _score: "0.623313",
    _string: "catamaran"
      _score: "0.099451",
      _string: "dock, dockage, docking facility"
      _score: "0.0621891",
      _string: "liner, ocean liner"
      _score: "0.0246246",
      _string: "fireboat"
      _score: "0.0244034",
      _string: "speedboat"
Prediction engine is 62% sure that the image is of a catamaran. Close enough.

Now, I could hook this up to my WhatsApp bot. I used yowsup python library to get this up and running. I just had to register my spare mobile number with WhatsApp server. With a bit of fiddling around, the bot was ready to talk to the prediction API.
Now I can send a picture, and get back the prediction in JSON format.