Skip to content

j-dong-cs/Handwritten_Digits_Recognition

Repository files navigation

Handwritten_Digits_Recognition

A web service of recognizing digits on image.

  • Build Image Preprocess Pipeline.

    • Convert to GrayScale

      org gray

    • Apply Gaussian Blur

      org blur

    • Apply threshold and invert colors

      org thresh

    • Use Canny Edge Detection to find edges

      org edges

    • Dilate Edges found

      org dilate

    • Find Contours and bouding box for each digit boundingbox

    • Extract each digit with boarder added to improve performance

      0 1 2 3 4 5

  • Import MNIST digits data.

  • Build and Train a Deep Neural Network Model to predict digits based on image pixels.

    • Convolutional Neural Network Pipeline: CNN pipeline

    • Model performance

      # calculate accuracy on the prediction
      acc = np.average(Y_pred == Y_true)
      print('Accuracy is', acc)
      Accuracy is 0.9912857142857143
      Attempted to log scalar metric accuracy:
      0.9912857142857143
  • 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]