Face Detection

This guide includes an example script to run face detection inference with OpenVINO Model Server.

  • The script face_detection.py runs face detection inference requests for all the images saved in image_input_dir directory.

  • The script can adjust the input image size and change the batch size in the request. It demonstrates how to use the functionality of dynamic shape in OpenVINO Model Server and how to process the output from the server.

  • The example relies on the model face_detection_0004.

Running the Script

python face_detection.py --help
usage: face_detection.py [-h] [--input_images_dir INPUT_IMAGES_DIR]
                         [--output_dir OUTPUT_DIR] [--batch_size BATCH_SIZE]
                         [--width WIDTH] [--height HEIGHT]
                         [--grpc_address GRPC_ADDRESS] [--grpc_port GRPC_PORT] [--model_name]

optional arguments:
  -h, --help            show this help message and exit
  --input_images_dir INPUT_IMAGES_DIR
                        Directory with input images
  --output_dir OUTPUT_DIR
                        Directory for staring images with detection results
  --batch_size BATCH_SIZE
                        how many images should be grouped in one batch
  --width WIDTH         how the input image width should be resized in pixels
  --height HEIGHT       how the input height should be resized in pixels
  --grpc_address GRPC_ADDRESS
                        Specify url to grpc service. default:localhost
  --grpc_port GRPC_PORT
                        Specify port to grpc service. default: 9000
  --model_name MODEL_NAME
                        Specify the model name

Usage example

Start the OVMS service locally:

curl --create-dirs https://download.01.org/opencv/2021/openvinotoolkit/2021.1/open_model_zoo/models_bin/1/face-detection-retail-0004/FP32/face-detection-retail-0004.xml https://download.01.org/opencv/2021/openvinotoolkit/2021.1/open_model_zoo/models_bin/1/face-detection-retail-0004/FP32/face-detection-retail-0004.bin -o model/1/face-detection-retail-0004.xml -o model/1/face-detection-retail-0004.bin
docker run -d -v $(pwd)/model:/models -p 9000:9000 openvino/model_server:latest  --model_path /models --model_name face-detection --port 9000  --shape auto

Run the client:

cd example_client
virtualenv .venv
. .venv/bin/activate
pip install -r client_requirements.txt
mkdir results

python face_detection.py --batch_size 1 --width 300 --height 300


python face_detection.py --batch_size 4 --width 600 --height 400 --input_images_dir images/people --output_dir results

Output of the Script

  • The script will visualize the inference results on the images saved in the directory output_dir. Saved images have the following naming convention:


The Face Detection Example script can be a reference script to run various other Detection models. Run through the following steps to use Person-Vehicle OpenVINO Model with OpenVINO Model Server.

Download the model from OpenVINO Model Zoo.

  • A variety of OpenVINO Models in IR format are present in OpenVINO Model Zoo. You can also convert your model to IR format (.xml and .bin format).

  • Refer to Model Optimizer to convert your model.

Create a model folder and download Person-Vehicle-Detection Model:

curl --create-dirs https://download.01.org/opencv/2021/openvinotoolkit/2021.1/open_model_zoo/models_bin/1/person-vehicle-bike-detection-crossroad-0078/FP32/person-vehicle-bike-detection-crossroad-0078.bin https://download.01.org/opencv/2021/openvinotoolkit/2021.1/open_model_zoo/models_bin/1/person-vehicle-bike-detection-crossroad-0078/FP32/person-vehicle-bike-detection-crossroad-0078.xml -o model/1/person-vehicle-bike-detection-crossroad-0078.bin -o model/1/person-vehicle-bike-detection-crossroad-0078.xml

Prepare Model Repository

Refer to Preparation of Models to place your downloaded or converted models in a repository to mount them to the OpenVINO Model Server.

Run the OpenVINO Model Server Docker Container

Run the OpenVINO Model Server with the downloaded models. Adjust the shape and batch_size parameter according to the requirement of the model. Refer this guide to know more about the parameters.

  • Run the following command on your terminal

docker run -d  -u $(id -u):$(id -g) -v $(pwd)/model:/models/person-detection -p 9000:9000 openvino/model_server:latest --model_path /models/person-detection --model_name person-detection --port 9000  --shape auto

Check if the container is running with :

docker ps

If the container is not running, check out the troubleshooting guide

Run the example script

Run the face detection example script - FaceDetection.py. Make changes to the input shape as required by the model you are running. Refer to the API reference Guide to obtain the input and output shape of the model - gRPC reference guide and REST API reference guide.

Run the example script in terminal :

python face_detection.py --batch_size 1 --width 600 --height 400 --input_images_dir images --output_dir results --model_name person-detection

Output of the Script

  • The image with inference is stored in the results folder. The inference bounding boxes are drawn around people and vehicles present in the image