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.

Github星跟踪图

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

  • Clone this repo
  • Install requirements
  • Run the script
  • Check http://localhost:5000
  • Done! :tada:

:point_down:Screenshot:


Docker Installation

Build and run an image for keras-application pretrained model

$ cd keras-flask-deploy-webapp
$ docker build -t keras_flask_app .
$ docker run -d -p 5000:5000 keras_flask_app 

Build and run an image from your model into the containeri.

After build an image as above, and

$ docker run -e MODEL_PATH=/mnt/models/your_model.h5  -v volume-name:/mnt/models -p 5000:5000 keras_flask_app

Pull an built-image from Docker hub

For your convenience, can just pull the image instead of building it.

$ docker pull physhik/keras-flask-app:2 
$ docker run -d -p 5000:5000 physhik/keras-flask-app:2

Open http://localhost:5000 after waiting for a minute to install in the container.

Local Installation

Clone the repo

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

Install requirements

$ pip install -r requirements.txt

Make sure you have the following installed:

  • tensorflow
  • keras
  • flask
  • pillow
  • h5py
  • gevent

Run with Python

Python 2.7 or 3.5+ are supported and tested.

$ python app.py

Play

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


Customization

Use your own model

Place your trained .h5 file saved by model.save() under models directory.

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

主要指标

概览
名称与所有者imfing/keras-flask-deploy-webapp
主编程语言JavaScript
编程语言Python (语言数: 5)
平台
许可证Apache License 2.0
所有者活动
创建于2018-02-04 18:49:54
推送于2024-03-24 20:14:23
最后一次提交
发布数3
最新版本名称v0.1.1 (发布于 )
第一版名称legacy (发布于 )
用户参与
星数1.2k
关注者数30
派生数470
提交数56
已启用问题?
问题数27
打开的问题数0
拉请求数12
打开的拉请求数1
关闭的拉请求数27
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?