Building Web App for Computer Vision Model & Deploying to Production in 10 Minutes*: A Detailed Guide
By: Pankaj Mathur
Tags: Google, Computer Vision, Keras, Docker, Deep Learning

UPDATES on August 23rd, 2020: The world has changed a lot, since i updated this article, so does fastai and keras libraries, Fastai has released version 2 which is complete rewrite of fastai, so does keras, which is now part of tensorflow2. I have also released updated starter pack for both fastai and keras, please download them here:

Fastai version 2:

git clone https://github.com/psmathur/fastai2-vision-app

Keras (under tensorflow2)

git clone https://github.com/psmathur/keras-vision-app

UPDATES on January 4th, 2019: Added one more deployment option: “Render” a new simplest yet powerful Docker-based web service hosting providers & much more.

UPDATES on Dec 4th, 2018: I am not sure, I want to continue using Zeit services, as Zeit has recently put a lot of changes to restrict 100 MB limits. I was not able to resolve 100 MB limit issue even when I have unlimited paid plan and even when I try to explicitly use version 1 of the platform via CLI with “now.json”. IMHO, They are definitely missing huge business opportunities here by restricting themselves with 100 MB Limits!

********************************************************

So, you have built an awesome Image Classification model using the famous deep learning libraries like Fast.AI or Keras, then wrote an article about it, while explaining how your model can classify various types of blue jay birds, plant diseases, Italian food, french fries, Swiss watches or can even predict composer of the classical music playing around you, using spectrogram of audio files (and you thought Image Classification was over-hyped for nothing).

Now, What next?

Well, more than just writing a technical blog post on how you have built an amazing Computer Vision model, you also want to share your work easily with your co-workers, friends, families, or anyone who has a device with a web browser. You want to share your work with them because they all can quickly test & provide valuable feedback on your state of the art deep learning based model results, which is an important step towards evaluating your final DL models.

You need a Demo Web App!

Let’s say you have built an Image Classification algorithm, and now needs a simple web app which can handle your image or pictures upload from a web browser in an asynchronous way, then it also needs to download your trained model, hosted some other place, in an asynchronous fashion.

Deep Learning models are heavy, you know a huge size multi-dimensional activations matrixes, so they need to be uploaded independently on some cloud storage services, plus you want to have an option to switch to a better-upgraded model, especially based upon the feedback you received, without changing & re-deploying underlying web app.

Then this web app also should be able to load your models in the memory of the machine, using your preferred deep learning libraries, and then it can predict labels on your uploaded image.

In the end, all this stuff need to be configured, deployed and hosted on some cloud hosting provider. Sound fun, right…

Well, we all know it’s not, any of those steps mentioned above, can end up taking a huge amount of time, if you don’t have an established process, especially during bug fixing or deployment configuration. So, to cut down all these steps to a minimum, I wrote this guide. Once, you followed this article, you will have a 3 (or 2) step process, by which you can quickly build a web app for your computer vision models & can deploy them to production in < 10 Minutes.

Here is the link of a sample web app: https://keras-vision.app.render.com/

index.html

To build and deploy this kind of web app, First, we are going to download or clone starter packs hosted on my GitHub repo, currently, these web app starter packs are for build only for computer vision models build with Keras and Fast.AI.

These starter packs contain a simple responsive web app which is built on top of Starlette.io & Uvicorn ASGI server. After downloading one of these starter packages, you only need to change a few lines of code to make your deep learning model, up and running on a local machine.

Second, we are going to use one of the Docker hosted services. We will take our static web app directory with docker configuration in it, and then deploy it to production to one of these fully managed dockers hosted services.

In this article, I am covering, AWS BeanStalk, Azure Web App and Now Version 1. However, you can use similar steps to deploy to any of the other Docker hosted services.

So, now, without further ado, let’s start with step 1.