GithubHelp home page GithubHelp logo

allenstin / image_recognition_serving_api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zihuaweng/image_recognition_service_api

0.0 0.0 0.0 29 KB

Easy way to deploy multiple models with deep learning frameworks for your products.

License: MIT License

Python 99.57% Shell 0.43%

image_recognition_serving_api's Introduction

Api for image recognition serving

Easy way to deploy multiple models with deep learning frameworks for your products.

深度学习模型多模型线上部署API. 可根据需要快速部署tensorflow, Keras模型(flask + gevent + gunicorn). 有更高级的需求可以使用tensorflow serving

My test environment:

  • Ubuntu 16.04
  • python3

Installation

python setup.py build
python setup.py install

Usage

from img_recog_api.model_creator import ImageModelSingle

config = 'path/to/config'

# image recognition
# create and load models
Model_s = ImageModelSingle(config)
# load image to api support format
image = your_load_image_func(image)
# predict image
results_s = Model_s.predict(image, top=4)

configs

Contains all config files.

  • config.yaml
model_type: SingleTf
model_file: /path/to/model.pb
label_file: /path/to/labels.txt
# gpu_num could be set as any int. for cpu using gpu_num: ""
gpu_num: 0
input_tensor: input tensor name of tensorflow model(eg: Placeholder:0), if None, find it with pattern
output_tensor: output tensor name of tensorflow model(eg: Prediction:0), if None, find it with pattern

Outputs

ImageModelSingle()

model_type=SingleTf

**result = model.predict(image, top)**

{
  "recognitionList": [
    {
      "className": "label1",
      "confidence": 0.2440231442451477
    }
  ]
}

Add your own model

Just over write the sub_models.py and add new class for your model like the example SingleTf.

Deploy your models

In this demo, I deployed a serving model with python using flask + gevent + gunicorn.

Is easy to deploy multiple models in this way. But tensorflow serving maybe a good choose for long-term use.

How to use it:

  • cd to example folder.
  • add your prediction scripts in sub_model.py and install the api.
  • change config.yaml according to your models.
  • add config information in gunicorn.config. For detail information pleae view gunicorn setting document
  • change image_recognition_all.py.

Run the server:

sh ./example_run.sh

Test it:

python example/service_test.py

TODO

  • remove the warm-up part (If anyone comes up a good idea to speed up the first test, feel free to contact me :) )

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.