Image Classification Demo (Go)

This client demonstrates how to interact with OpenVINO Model Server prediction endpoints from a Go application. The example shows end-to-end workflow for running classification on JPEG/PNG images using a ResNet50 model. To simplify the environment setup, the demo is run inside a Docker container.

Get the model

To run end to end flow and get correct results, please download resnet-50-tf model and convert it to IR format by following instructions available on the OpenVINO Model Zoo page

Place converted model files (XML and BIN) under the following path: <PATH_TO_MODELS>/resnet/1

Where PATH_TO_MODELS is the path to the directory with models on the host filesystem.

For example:

/home/user/models/resnet/1/resnet-50-tf.xml
/home/user/models/resnet/1/resnet-50-tf.bin

Build Go client docker image

Before building the image let’s copy single zebra image, here so it’s included in the docker build context. This way client container will already have a sample to run prediction on:

cp ../../common/static/images/zebra.jpeg .

Then build the docker image and tag it ovmsclient :

docker build . -t ovmsclient

Start OpenVINO Model Server with ResNet model

Before running the client launch OVMS with prepared ResNet model. You can do that with a command similar to:

docker run -d --rm -p 9000:9000  -v <PATH_TO_MODELS>/resnet:/models/resnet openvino/model_server:latest --model_name resnet --model_path /models/resnet --port 9000 --layout NHWC:NCHW

Note Changing the layout with --layout NHWC:NCHW option is necessary in this example, so the model will accept binary input generated by the client. See binary inputs doc if you want to learn more about this feature.

Run prediction with Go client

In order to run prediction on the model served by the OVMS using Go client run the following command:

docker run --net=host --rm ovmsclient --serving-address localhost:9000 zebra.jpeg

Command explained:

  • --net=host option is required so the container with the client can access container with the model server via host network (localhost),

  • --serving-address parameter defines the address of the model server gRPC endpoint,

  • the last part in the command is a path to the image that will be send to OVMS for prediction. The image must be accessible from the inside of the container (could be mounted). Single zebra picture - zebra.jpeg - has been embedded in the docker image to simplify the example, so above command would work out of the box. If you wish to use other image you need to provide it to the container and change the path.

You can also choose if the image should be sent as binary input (raw JPG or PNG bytes) or should be converted on the client side to the data array accepted by the model. To send raw bytes just add --binary-input flag like this:

docker run --net=host --rm ovmsclient --serving-address localhost:9000 --binary-input zebra.jpeg

Exemplary output:

If the client successfully prepared and sent the request and then received a valid response, the output of this command should look somewhat like this:

$ docker run --net=host --rm ovmsclient --serving-address localhost:9000 zebra.jpeg
2021/08/30 15:46:40 Request sent successfully
Predicted class: zebra
Classification confidence: 98.353996%