Deep learning API¶
app.helpers module¶
Helper funcation for preprocessing
app.run_model_server module¶
Run deep learning model which predication the classes and update predication
to redis database with id and json
-
app.run_model_server.classify_process()[source]¶ Load the pre-trained Keras model (here we are using a model pre-trained on ImageNet and provided by Keras, but you can substitute in your own networks just as easily.
Note
In this example we load
Resnet50trained onimagenet.Images stored in redis after pre-processing, we take images in batch from
redisdatabase and predicat the class. Than result are saved toredisaskey(id):predicated(json)
app.run_web_server module¶
Make flask server to preprocess the the image and add queue to
redis database. Then check if predication is saved to redis database,
once predication is saved, return the predication json.
-
app.run_web_server.predict()[source]¶ Predicat the image class.
Send the image as post request.
curl -X POST -F image=@jemma.png 'http://localhost/predict'
- Return:
json of classes from predication
{ "predictions": [ { "label": "beagle", "probability": 0.9461532831192017 }, { "label": "bluetick", "probability": 0.031958963721990585 }, { "label": "redbone", "probability": 0.0066171870566904545 }, { "label": "Walker_hound", "probability": 0.003387963864952326 }, { "label": "Greater_Swiss_Mountain_dog", "probability": 0.0025766845792531967 } ], "success": true }
app.settings module¶
Environment variables for app
# initialize Redis connection settings
REDIS_HOST = "redis"
REDIS_PORT = 6379
REDIS_DB = 0
# initialize constants used to control image spatial dimensions and
# data type
IMAGE_WIDTH = 224
IMAGE_HEIGHT = 224
IMAGE_CHANS = 3
IMAGE_DTYPE = "float32"
# initialize constants used for server queuing
IMAGE_QUEUE = "image_queue"
BATCH_SIZE = 32
SERVER_SLEEP = 0.25
CLIENT_SLEEP = 0.25