Go client for prediction
This client has been created to demostrate how to interact with OpenVINO Model Server prediction endpoint from Go application. Presented example demonstrates end to end flow for running classification on JPG/PNG image using ResNet50 model. For simplicity of the environment setup, the example is run in the 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
To build the docker image and tag it ovmsclient
run:
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
Note Changing the layout with --layout NHWC
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%