Bring Custom Vision into Azure IoT Edge


The Custom Vision Service is a Microsoft Cognitive Service that lets you build custom image classifiers. It makes it very easy and fast to build, deploy, and improve an image classifier. Since May 7, we are able to export tensorflow model to Dockerfile in custom vision service, that means we can download the artifacts to build our own windows or Linux containers, and furthermore, deploy it to Iot Edge. Notice that Custom Vision Service only support export in compact domains. The models generated by compact domains are optimized for the constraints of real-time classification on mobile devices and classifiers built with a compact domain may be slightly less accurate than a standard domain with the same amount of training data.

After uploading the images and finishing the training, we can find the Export button in PERFORMANCE page and make sure export as DockerFile. The exported artifact is actually a fully functional http server which is listening on 80 port. In order to use it in Iot Edge, the easiest way is keep it as a http server and call the web service from other custom module shown below.

Any module deployed by edge agent will be located in azure-iot-edge network shown below, that means you don't need to make any port mapping explicitly and the http service can be accessed by other module via http://[module name]:[port number] directly.

In order to create a custom module to call the AI module, we can make it either by cookiecutter, or from visual studio code. Make sure "Azure Iot Toolkit" has been installed to Visual studio code, we will be able to "New IoT Edge Solution" via Command Palette shown below.


Certainly, we can modify the exported AI module to a custom module as well, in that case the module will need take care of message input and output as well.

On the other hand, I also see some scenario that it is required to access the http service from non-container. It is easy to make port mapping in "Container Create Options" shown below.

The below code has exported the http server on port 8085 and the edge host will be able to access it via port 8085. For all the other available options ,please refer to https://docs.docker.com/engine/api/v1.30/#operation/ContainerCreate

{
  "HostConfig": {
    "PortBindings": {
      "80/tcp": [
        {
          "HostPort": "8085"
        }
      ]
    }
  }
}
Comments (0)

Skip to main content