How-to Guide: CNNs using TensorFlow / Keras / TensorFlow Serving in Google Colaboratory

TensorFlow | Keras | Colaboratory

Google recently launched Colaboratory, a tool that lets you run Jupyter notebooks in the cloud by hooking them up with your Google Drive. This is a great step in making machine learning and data science accessible to everyone. Now it doesn’t matter whether you have a fancy computer or not, you can access all the tools you need right from your browser. It also makes collaborating on code with anyone you like as editing a document together in Google Drive.

For me, the best part is that I don’t have to install anything on my computer to get started. This came in very handy as I was designing a walk-through of how to train a TensorFlow image classification model (convolutional neural network or CNN) using Keras, serve this model using TensorFlow Serving and create a prediction service to run inference on images in real time. I put all the code in Colaboratory notebooks and now I don’t have to ask the audience to download a Docker container with all the prerequisites — neat!

To sum it all up, Colaboratory is a means to an end. The end I hope for here is that you enjoy my three part series on how to train and serve a CNN model using TensorFlow (+Keras) and TensorFlow Serving, respectively. All the notes and explanations for each step are within the notebooks to keep them as self-contained as possible.

Before you open the Colaboratory notebooks linked below, you will need to sign up for Colaboratory (essentially link your Google drive to Colaboratory)using this link. It’s super easy and non-intrusive, I promise. Let’s face it, you’d rather do this (and let Google do the work for you) than download some multi-MB Docker image that I put together (and have to debug all the issues yourself). If you’re new to Colaboratory, read the steps described after the links.

Part 1: Convolutional Neural Network for Image Classification using TensorFlow and Keras

Part 2: Serve trained TensorFlow model using TensorFlow Serving

Part 3: Prediction service using TensorFlow Serving API

Once you open the notebooks, you will see a preview of the notebook and you can click on “Open With Colaboratory” at the top or navigate to “Open With” drop-down and select “Colaboratory”.

Select “Open with Colaboratory”

At this point you will be able to see the code and saved output in the notebooks. You will notice that the “Insert” and “Runtime” menus are both inactive. In order to edit the code or run it yourself, you will need to copy the notebook to your own Google Drive. Click “File” → “Save a Copy in Drive…”

Select “Save a Copy in Drive…”

A copy of that notebook will open in your Drive in a new tab of your browser. You can use this copy to edit and run the code as you see fit. To run all the cells, “Runtime” → “Run all” or shift+Enter to run the current cell.

PS — I suggest you open the notebooks in Chrome. Even though Colaboratory supports both Firefox and Chrome, I could not get my notebooks to open up in Firefox with the shareable link. ?‍♀️

Source: Deep Learning on Medium