82. Building an Image Classification Inference Service#
82.1. Introduction#
In the previous experiments and challenges of image classification, we used the pre-trained models provided by TensorFlow Keras to complete the cat and dog recognition task. In this challenge, you need to try to build a real-time inference API interface for image classification using the pre-trained models provided by TensorFlow Keras.
82.2. Key Points#
Pre-trained models
TensorFlow Keras
Flask Web API
In the relevant experiments and challenges of transfer learning, we have used the MobileNetV2 pre-trained model provided by Keras. The size of this model after training on ImageNet is 14MB. In this challenge, you need to utilize the MobileNetV2 pre-trained model and combine it with the Flask Web framework used in the deployment of scikit-learn models to build a real-time inference API for image classification.
{exercise-start}
:label: chapter10_05_1
Open-ended Challenge
Challenge: Implement a real-time inference API for image classification built with the MobileNetV2 pre-trained model, and be able to perform inference on any image passed in via a POST request.
Hint: Please use various tools such as search engines to think and solve this problem on your own. The implementation method is not fixed, but the result should be similar to the expected output.
{exercise-end}
{solution-start} chapter10_05_1
:class: dropdown
huhuhang/mobilenet_v2-imagenet-api
{solution-end}
Expected output:
We expect to be able to perform inference on any image. It is recommended that you implement it in a Linux environment. The Notebook environment is not suitable for building a Flask application, but you can imitate the method of using subprocesses in the previous experiments to complete it.
The final implementation effect of the challenge is roughly as follows. We expect to output the top 5 classification categories with the highest probabilities in ImageNet and their corresponding probability values for any local image.