Build and deploy a simple classifier API using rorodata

rorodata
rorodata
Published in
5 min readMay 25, 2018

Learn how to deploy your machine learning model to the web

Tutorial

The real value of a machine learning model in the wild is when it is deployed for others to use. We want you share your models with the world. In this tutorial, you will learn how to deploy a simple image recognition API to the web.

This tutorial has two parts:

  1. Setup: Use the VGG16 pre-trained model (Image-net) to build a simple classifier
  2. Deploy: Learn how to deploy a classifier with rorodata

We will not be going into the details of how to do pattern recognition or how to build a classifier. There are quite few well written resources online such as this one.

Setting-up the project

Getting started with rorodata

The easiest way to get started with rorodata is by signing-up, following the the quickstart instructions in the docs. When using web dashboard, there is no need for any local download or installation.

Create a new project

A project in rorodata is the basic workspace unit — all related experiments, deployments can be grouped in single project. Create a new project using the button in the menu bar.

Create a new project

After you create the project, you will see the project dashboard, which looks something like the following, of course your page will be empty for now.

Project Dashboard

Building a classifier

Start the development

We will start the development of our prediction model by starting a Jupyter Lab environment. Click the New Jupter Lab (Beta) , select the appropriate hardware (we have three hardware options S2, M1 and G1). Sit-back and wait for the environment to prepare. In the background, the platform creates a containerized environment for your development work. For more information on Jupyter Lab, see this.

JupterLab Development Environment

Download a repo from Github

Let’s download a repo from GitHub to get started with the interesting part. Click on the Terminal tab and type bash to get a command prompt that looks something like root@92hg3982des0:/volumes/notebooks . Let’s clone a project with git clone https://github.com/rorodata/image-recognition-demo.git and cd into image-recognition-demo

Open the jupyter notebook from the project files to check the machine learning code. You screen will look something like the following:

Building model

Scroll down through the notebook, checkout the Keras code for object detection. It uses the pre-trained VGG16 model for prediction. Now let’s deploy this as an API to the web.

Deployment

Deploy the model as RESTful API

At this point most data scientists look to write a Flask application to serve the model as a RESTful API, some use the Tensorflow Serving. Flask is the most preferred approach as none of the other frameworks (other than tensor flow) provide a native serving mechanism. Don’t worry rorodata has you covered.

Deploying on rorodata is simple, all you need is a simple configuration file called roro.yml this is already present in the project folder. This is config file is required for all deployments and trainings.

Before we move to roro.yml let’s write a prediction function for our model in file predict.py (this file is already present in the repo).

predict.py contains prediction function

With prediction.py in place let’s modify the roro.yml configuration.

That’s it, we are all set. roro deploy to deploy the model as an API. Ensure you are in the correct folder image-recognition-demo in this case or whatever name you have given the folder. The will be active in 5–10 seconds.

The API can consume any JSON friendly format or binary objects as inputs. Support for more formats is in the works.

Successful deployment of API

Consuming the API

The live API is a RESTful service which can be consumed using any standard requests library. However, to make life a little easy we give you simple client library to consume the API.

Please note the API requires the function and argument to be correctly specified -under-the-hood this predict function is deployed as a service.

That’s it. You can build, prototype and deploy any machine learning or deep learning model without much overheads.

Bonus — one page app for your API

You can also include a simple one-page app for your API. We have provided a small folder that contain static files — check html folder in the repo. Let’s modify the roro.yml before we deploy the app.

Now, run roro deploy from the CLI and we’re done. Your services will be active at the following endpoints:

API: https://<your-project-name>--api.rorocloud.io/
APP: https://<your-project-name>.rorocloud.io/

Please note the change in the URL endpoints.

We encourage you to experiment, build and deploy other interesting machine learning applications and share it with the world.

Please do write to us with your feedback and comments. If you are a company/startup looking for help with machine learning, we’d be more than happy to help. Just drop us a line and we’ll get back.

--

--