#AzureIoT – How to create an Azure IoT module from an Azure #CustomVision project 👀 2/N

Buy Me A Coffee

Hi !

In my previous post I wrote about how to create an Azure Custom Vision project. And, once created how to export the project as a Docker image to be used in different platforms. So, let’s take a look at the content of the exported Linux image.

The main docker content is described in the image below. We can find

  • Folder app. This folder hosts the computer vision exported model (model.pb), and the python files to perform the object detection, and to host this as as a webserver using flask.
  • Folder azure ml. This folder contains a step-by-step instruction on how to use this in Azure ML. Also a python file to analyze and perform the scores on images.
  • Root files. dockerfile to build the image, license and readme.
custom vision exported to Linux contents

The docker file is very straightforward.

  • It’s based on a Python 3.7 slim image
  • Install the following prerequisites: numpy, tensorflow, flask, pillow, mscviplib
  • Opens the port 80
  • Run the python app in the file [app/app.py]
FROM python:3.7-slim

RUN pip install -U pip
RUN pip install --no-cache-dir numpy~=1.17.5 tensorflow~=2.0.2 flask~=1.1.2 pillow~=7.2.0
RUN pip install --no-cache-dir mscviplib==2.200731.16

COPY app /app

# Expose the port
EXPOSE 80

# Set the working directory
WORKDIR /app

# Run the flask server for the endpoints
CMD python -u app.py

And finally, let’s take a look at the [app/app.py]. I cropped some of the code for a better readability.

  • Creates a Flask app
  • Create an Http POST endpoint [/image] which receive a file to perform the object detection
  • Create an Http POST endpoint [/url] which receive a file location (url) to perform the object detection
import json
import os
import io

# Imports for the REST API
from flask import Flask, request, jsonify

# Imports for image procesing
from PIL import Image

# Imports for prediction
from predict import initialize, predict_image, predict_url

app = Flask(__name__)

# 4MB Max image size limit
app.config['MAX_CONTENT_LENGTH'] = 4 * 1024 * 1024 

# Default route just shows simple text
@app.route('/')
def index():
    return 'CustomVision.ai model host harness'

@app.route('/image', methods=['POST'])
def predict_image_handler(project=None, publishedName=None):

@app.route('/url', methods=['POST'])
def predict_url_handler(project=None, publishedName=None):

if __name__ == '__main__':
    # Load and intialize the model
    initialize()

    # Run the server
    app.run(host='0.0.0.0', port=80)


So, we have everything to analyze images !

In my next post, let’s start the update process to update this docker image to run as an Azure IoT Module !

Resources

Happy coding!

Greetings

El Bruno

More posts in my blog ElBruno.com.

More info in https://beacons.ai/elbruno



Azure ☁ IoT

Create an Azure IoT Module using Raspberry Pi and Grove Sensors

  1. Raspberry Pi + Grove Sensors, read temperature and humidity values
  2. Raspberry Pi + Grove Sensors, send temperature and humidity values as telemetry to Azure IoT Hub
  3. Raspberry Pi + Grove Sensors, create a Azure IoT Module to send temperature and humidity values as telemetry to Azure IoT Hub
  4. Raspberry Pi + Grove Sensors, publish and use the Azure IoT Module
  5. Raspberry Pi + Grove Sensors, notes on build and configuration
  6. Raspberry Pi + Grove Sensors, details on how to send a telemetry message and sample messages

Create an Azure IoT Module from Azure Custom Vision project


¿Con ganas de ponerte al día?

En Lemoncode te ofrecemos formación online impartida por profesionales que se baten el cobre en consultoría:

Advertisement

1 comment

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: