manjrekarom / keras-flask-deploy-webapp

:smiley_cat: Pretty&simple image classifier app template. Deploy your own trained model or pre-trained model (VGG, ResNet, Densenet) to a web app using Flask in 10 minutes.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Deploy Keras Model with Flask as Web App in 10 Minutes

GPLv3 license

A pretty and customizable web app to deploy your DL model with ease


Getting started in 10 minutes

👇Screenshot:


Local Installation

Clone the repo

$ git clone https://github.com/manjrekarom/keras-flask-deploy-webapp.git

Install requirements

$ pip install -r requirements.txt

Make sure you have the following installed:

  • tensorflow
  • pytorch
  • torchvision
  • keras
  • flask
  • pillow
  • h5py
  • gevent

Run with Python

Python 2.7 or 3.5+ are supported and tested.

Examples:

  1. To start serving a pretrained keras model:
$ python app.py
  1. Alternatively, you can specify pytorch models, image size and class categories for custom models.
$ python app.py -t ./models/animal/cnn.pkl -d 112 112 -c ./models/animal/class.txt --delim " "
  1. For usage details:
$ python app.py -h

Play

Open http://localhost:5000 and have fun. 😃


Customization

Use your own model

Place your trained .h5 (for keras) or .pkl (for PyTorch) file saved by model.save() under models directory (preferrably) or specify a path to it.

Check the commented code in app.py.

Use other pre-trained model

See Keras applications for more available models such as DenseNet, MobilNet, NASNet, etc.

Check this section in app.py.

UI Modification

Modify files in templates and static directory.

index.html for the UI and main.js for all the behaviors

Deployment

To deploy it for public use, you need to have a public linux server.

Run the app

Run the script and hide it in background with tmux or screen.

$ python app.py

You can also use gunicorn instead of gevent

$ gunicorn -b 127.0.0.1:5000 app:app

More deployment options, check here

Set up Nginx

To redirect the traffic to your local app. Configure your Nginx .conf file.

server {
    listen  80;

    client_max_body_size 20M;

    location / {
        proxy_pass http://127.0.0.1:5000;
    }
}

More resources

Check Siraj's "How to Deploy a Keras Model to Production" video. The corresponding repo.

Building a simple Keras + deep learning REST API

Todos

  • Showing top N classes
  • Manual cropping
  • Visualization of learned features (saliency maps, grad-CAMs, etc).
  • Support for different types models and frameworks

About

:smiley_cat: Pretty&simple image classifier app template. Deploy your own trained model or pre-trained model (VGG, ResNet, Densenet) to a web app using Flask in 10 minutes.

License:GNU General Public License v3.0


Languages

Language:Python 60.9%Language:HTML 15.8%Language:JavaScript 12.5%Language:CSS 7.7%Language:Dockerfile 3.1%