A web service of recognizing digits on image.
-
Build Image Preprocess Pipeline.
-
Import MNIST digits data.
-
Build and Train a Deep Neural Network Model to predict digits based on image pixels.
-
Store the DNN model into an ONNX:Open Neural Network Exchange instance.
-
Load and Register the ONNX model into Azure.
-
Create a Docker Image of the registered model, score.py script, and YAML envrionment dependencies file.
-
Deploys the scoring image on Azure Containter Instance (ACI) as a web service.
-
Client convert image into bytes array and serialize it into JSON str.
-
Client send a HTTP request with JSON str to digits recognition web service.
-
The web service decode JSON str into bytes array which is sent to CNN model to predict digits on the image.
-
The prediction of digits are returned to the client.
import os import json import base64 import requests image_path = os.path.join(os.getcwd(), 'test1.jpg') with open(image_path, 'rb') as file: img = file.read() image_64_encode = base64.encodebytes(img).decode('utf-8') bytes_to_json = json.dumps(image_64_encode) scoring_url = 'http://3ab34ad2-281d-4017-b47f-7a099895a46b.centralus.azurecontainer.io/score' headers = { 'Content-Type': 'application/json' } response = requests.post(scoring_url, bytes_to_json, headers=headers) print(json.loads(response.text)) [0, 7, 1, 3, 8, 9]