Git Product home page Git Product logo

flask-tensorflow's Introduction

Process from training with estimator to serving with flask

  • Dataset: MNIST dataset from Keras
  • Training Method : Tensorflow Estimator
  • One of the MNIST datasets is randomly selected to show the predicted result and label.

File explaination

  • modeling.py : make model for tensorflow estimator
  • train.py : tensorflow training process
  • eval.py : evaluate tensorflow estimator model based on train.py
  • export.py : export freeze model from model made by train.py
  • serving_flask.py : serving freeze model with flask method

Requirements

  • tensorflow==1.14.0
  • numpy
  • flask
  • flask-restful

Command line

python train.py ## training
python eval.py ## evaluate
python export.py ## export model
python serving_flask.py ## serving by flask, you have to edit line 17(export file path)

Serving and Check by requests module

Serving

(xxx) xxx@xxx:~/flask-tensorflow$ python serving_flask.py 
WARNING: Logging before flag parsing goes to stderr.
W0831 03:19:47.895947 139689095231296 deprecation_wrapper.py:119] From serving_flask.py:19: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.

W0831 03:19:47.904812 139689095231296 deprecation_wrapper.py:119] From serving_flask.py:20: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.
...
...
XLA_FLAGS=--xla_hlo_profile.
 * Serving Flask app "serving_flask" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
I0831 03:19:48.059808 139689095231296 _internal.py:122]  * Running on http://0.0.0.0:3000/ (Press CTRL+C to quit)
I0831 03:20:00.875686 139682033678080 _internal.py:122] 127.0.0.1 - - [31/Aug/2019 03:20:00] "GET /api/test HTTP/1.1" 200 -

Check

Python 3.6.8 |Anaconda, Inc.| (default, Dec 30 2018, 01:22:34) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> res = requests.get('http://0.0.0.0:3000/api/test')
>>> print(res.json())
{'predict': [3], 'answer': 3}

flask-tensorflow's People

Contributors

chagmgang avatar

Watchers

 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.