GithubHelp home page GithubHelp logo

qqq-tech / keras-flask-deployment Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gsbyeon/keras-flask-deployment

0.0 1.0 0.0 24 KB

License: GNU General Public License v3.0

Dockerfile 3.88% Python 48.60% CSS 9.64% JavaScript 18.75% HTML 19.13%

keras-flask-deployment's Introduction

케라스 모델을 Flask서버에 올리기

GPLv3 license

거의 모든 코드는 https://github.com/mtobeiyf/keras-flask-deploy-webapp 를 수정한 것 입니다.


Changelog

  • aws s3에 저장된 모델을 불러 사용 가능
  • index.py 에 argparse 추가 -- port: 포트지정 (default=8080) --model_path: 경로 모델에 있는 모델 사용(default=/tmp/model.h5) --framework: keras(케라스 모델 사용) / pytorch(pytorch 모델 사용) (default=keras) --from_s3: s3에 있는 모델을 로컬 파일로 저장 후 사용. default 저장경로 /tmp/model.h5
  • static/js/main.js 로직을 1개에서 3개의 카테고리가 나오게 변경

example usage:

python index.py --port 8080 --from_s3 s3://your_bucket/path_to_model --model_path /tmp/keras/model.h5

Docker Installation

Build the image

cd keras-flask-deploy-webapp
docker build -t keras_flask .
docker run -e MODEL_PATH=models/your_model.h5 -p 5000:5000

You can mount your model into the container.

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

Local Installation

Clone the repo

$ git clone https://github.com/JeonCS/keras-flask-deployment.git

Install requirements

$ pip install -r requirements.txt

Make sure you have the following installed:

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

Run with Python

Python 2.7 or 3.5+ are supported and tested.

$ python index.py

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

keras-flask-deployment's People

Contributors

jeoncs avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.