Image Recognition in Ruby Tensorflow

Developers for tensorflow.rb have been having a long discussion about developing something really cool with ruby tensorflow and so we decided to work on the Image recognition tutorial and got some really interesting results that we would like to share with you.

This blog post is a sequel to the introductory and developers blog post about ruby tensorflow. Please do read them, to learn more about interesting developments in tensorflow.rb Our main source of inspiration for the blog is the tensorflow image recognition tutorial.

Image Recognition

Our brains make vision seem easy. It doesn’t take any effort for humans to tell apart a lion and a jaguar, read a sign, or recognize a human’s face. But these are actually hard problems to solve with a computer: they only seem easy because our brains are incredibly good at understanding images.

In the last few years the field of machine learning has made tremendous progress on addressing these difficult problems. In particular, a kind of model called a deep convolutional neural network can achieve reasonable performance on hard visual recognition tasks — matching or exceeding human performance in some domains.

Researchers have demonstrated steady progress in computer vision by validating their work against ImageNet — an academic benchmark for computer vision. Successive models continue to show improvements, each time achieving a new state-of-the-art results. Google took this to the next step by releasing code for running image recognition on latest model, Inception-v3.

Inception-v3 is trained for the ImageNet Large Visual Recognition Challenge using the data from 2012. This is a standard task in computer vision, where models try to classify entire images into 1000 classes, like “Zebra”, “Dalmatian”, and “Dishwasher”. Inception-v3 reaches 3.46% error rate for top 5 results.

This tutorial will teach you how to use Inception-v3 in tensorflow.rb . You’ll learn how to classify images into 1000 classes in Ruby.


  • Clone and install tensorflow.rb
  • Go to image directory
  • Download this zip file from google
  • extract the file ‘tensorflow_inception_graph.pb’ in this directory.
  • Do ruby classify_image.rb (This will work on the default image of the Mysore palace).
  • To try this out on your own images you can add the image to this directory and then change file name in line 31 on classify_image.rb .


A few cool examples of using image recognition tutorial.

First let's try this out on a cute puppy

Image for post
Image for post

A palace?

Image for post
Image for post
Winter Palace, St. Petersburg

A library ?

Image for post
Image for post

Or a bridge ?

Image for post
Image for post
Széchenyi Chain Bridge, Hungary

The results are interesting, and I encourage you to play with tensorflow.rb and try it out on your own images. To gain a better understand of this. The deep learning model in Inception-v3, is described in Arxiv preprint “Rethinking the Inception Architecture for Computer Vision” and can be visualized with this schematic diagram:

Image for post
Image for post

As described in the preprint, this model achieves 5.64% top-5 error while an ensemble of four of these models achieves 3.58% top-5 error on the validation set of the ImageNet whole image ILSVRC 2012 classification task. Furthermore, in the 2015 ImageNet Challenge, an ensemble of 4 of these models came in 2nd in the image classification task.

With this, I will mark the completion of this blog. I hope you find this interesting and useful. Any suggestions and recommendations are most welcome. Feel free to comment your thoughts and suggestions below.

Do share this blog and have fun with tensorflow.rb .

Written by

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store