Jaa


Get Started with Cognitive Service Container in IoT Edge

In order to enable the developers to build AI system based on Azure cognitive service with low latency and better data governance, the cognitive services just launched Face, Recognize Text, and Text Analytics containers in public preview. That means the developers can use exactly the same intelligent APIs that are available in Azure, but with the flexibility that comes with Docker containers which can be deployed on premise, on the edge, or in the cloud. For more related information, please refer to Getting started with Azure Cognitive Services in containers and Bringing AI to the edge.

This article is about how to bring cognitive service container into iot edge, and I will use text analytics for example. Before moving forward, please refer to https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/how-tos/text-analytics-how-to-install-containers firstly. As you can see, the usage of cognitive service container is very straightforward to create cognitive service in azure, retrieve the key and endpoint, then just run it as a normal container with three command parameters:

ApiKey
The API key of the Text Analytics resource used to track billing information. The value of this option must be set to an API key for the provisioned Text Analytics Azure resource specified in Billing.

Billing
The endpoint of the Text Analytics resource used to track billing information. The value of this option must be set to the endpoint URI of a provisioned Text Analytics Azure resource.

Eula
Indicates that you've accepted the license for the container. The value of this option must be set to accept.

In order to bring the cognitive service container into iot edge, we just need create an iot edge custom module and specify Eula, Billing and ApiKey in container create options shown below.

In order to see the effect easily, we can map the container's port to host machine shown below:

 

{
"HostConfig": {
"PortBindings": {
"5000/tcp": [
{
"HostPort": "8085"
}
]
}
},
"Cmd": [
"Eula=accept",
"Billing=https://westus.api.cognitive.microsoft.com/text/analytics/v2.0",
"ApiKey=2bae6d626a3c44cf9e86dec697498611"
]
}

Then, I will be able to access the text analytics swagger API via host port directly which means the cognitive service container is running well now. And, we can either call the REST API operations available, or use the Azure Cognitive Services Text Analytics SDK client library for further text analytics operations.