A REST API Serving a Tensorflow 2 keras deep learning model to classify image
Since Tensorflow 2 Alpha was annonced recently, I wanted to try it out by making a simple image classification model trained on fashion mnist data set using a 3 layers neural networks. The model is served as a Rest API.
Defined classes are ‘T-shirt/top’, ‘Trouser’, ‘Pullover’, ‘Dress’, ‘Coat’, ‘Sandal’, ‘Shirt’, ‘Sneaker’, ‘Bag’, ‘Ankle boot’.
1- Install the required libs (with conda install
or pip install
).
2- Run python train_and_export_model.py
to train the deep neural networks and export to export it to fashion_mnist_classifier savedModel
.
3- Run python app.py
to start the server that runs the port 5000.
4- Send a POST query to the http://127.0.0.1/api/recognize_image
with a body consisting of a JSON content:
{
"img_url" : "<IMG_TO_CLASSIFY_URL> (http://www.stickpng.com/assets/thumbs/580b57fbd9996e24bc43bef3.png)"
}
And the Server should do the prediction and then respond with :
{
"data": {
"confidence": "89%",
"prediction": "Dress"
},
"isError": false,
"message": "Success",
"statusCode": 200
}