This tutorial explains how to convert real-time object detection YOLOv1*, YOLOv2*, and YOLOv3* public models to the Intermediate Representation (IR). All YOLO* models are originally implemented in the DarkNet* framework and consist of two files:
.cfgfile with model configurations
.weightsfile with model weights
Depending on a YOLO model version, the Model Optimizer converts it differently:
On GitHub*, you can find several public versions of TensorFlow YOLOv3 model implementation. This tutorial explains how to convert YOLOv3 model from the https://github.com/mystic123/tensorflow-yolo-v3 repository (commit ed60b90) to IR , but the process is similar for other versions of TensorFlow YOLOv3 model.
Originally, YOLOv3 model includes feature extractor called
Darknet-53 with three branches at the end that make detections at three different scales. These branches must end with the YOLO
Region layer was first introduced in the DarkNet framework. Other frameworks, including TensorFlow, do not have the
Region implemented as a single layer, so every author of public YOLOv3 model creates it using simple layers. This badly affects performance. For this reason, the main idea of YOLOv3 model conversion to IR is to cut off these custom
Region-like parts of the model and complete the model with the
Region layers where required.
To dump TensorFlow model out of https://github.com/mystic123/tensorflow-yolo-v3 GitHub repository (commit ed60b90), follow the instructions below:
To solve the problems explained in the YOLOv3 architecture overview section, use the
yolo_v3_tiny.json (depending on a model) configuration file with custom operations located in the
It consists of several attributes:
match_kindare parameters that you cannot change.
custom_attributesis a parameter that stores all the YOLOv3 specific attributes:
maskare attributes that you should copy from the configuration file file that was used for model training. If you used DarkNet officially shared weights, you can use
yolov3-tiny.cfgconfiguration file from https://raw.githubusercontent.com/pjreddie/darknet/master/cfg. Replace the default values in
custom_attributeswith the parameters that follow the
[yolo]title in the configuration file.
To generate the IR of the YOLOv3 TensorFlow model, run:
To generate the IR of the YOLOv3-tiny TensorFlow model, run:
OpenVINO™ toolkit provides a demo that uses YOLOv3 model. For more information, refer to Object Detection YOLO* V3 Demo, Async API Performance Showcase.
Before converting Choose a YOLOv1 or YOLOv2 model version that best suits your task. Download model configuration file and corresponding weight file:
cfgdirectory, links to weight files are given in the
README.mdfile. The files from this repository are adatped for conversion to TensorFlow using DarkFlow.
cfgdirectory of the repository, links to weight files are given on the YOLOv1 and YOLOv2 websites.
To convert DarkNet YOLOv1 and YOLOv2 models to IR, follow the next stepsg:
You need DarkFlow to convert YOLOv1 and YOLOv2 models to TensorFlow. To install DarkFlow:
README.mdfile in the DarkFlow repository.
To convert YOLOv1 or YOLOv2 model to TensorFlow, go to the root directory of the cloned DarkFlow repository and run the following command:
If the model was successfully converted, you can find the
<model_name>.pb files in
built_graph subdirectory of the cloned DarkFlow repository.
<model_name>.pb is a TensorFlow representation of the YOLO model.
Converted TensorFlow YOLO model is missing
Region layer and its parameters. Original YOLO
Region layer parameters are stored in the configuration
<path_to_model>/<model_name>.cfg file under the
To recreate the original model structure, use the
yolo_v1_v2.jsonconfiguration file with custom operations and
Region layer parameters when converting the model to the IR. This file is located in the
If chosen model has specific values of this parameters, create another configuration file with custom operations and use it for conversion.
To generate the IR of the YOLOv1 model, provide TensorFlow YOLOv1 or YOLOv2 model to the Model Optimizer with the following parameters:
--input_shapedefines shape of model input. In the example,
--batchis equal to 1, but other integers larger than 1 are also applicable.
Regionlayer to the model with the
RegionYoloname. For other applicable parameters, refer to Conver Model from TensorFlow.