To dump TensorFlow model out of https://github.com/mystic123/tensorflow-yolo-v3 GitHub repository (commit ed60b90), follow the instructions below:
- Clone the repository:
git clone https://github.com/mystic123/tensorflow-yolo-v3.git
cd tensorflow-yolo-v3 - (Optional) Checkout to the commit that the conversion was tested on:
git checkout ed60b90 - Download coco.names file from the DarkNet website OR use labels that fit your task.
- Download the yolov3.weights (for the YOLOv3 model) or yolov3-tiny.weights (for the YOLOv3-tiny model) file OR use your pretrained weights with the same structure
- Run a converter:
- for YOLO-v3: python3 convert_weights_pb.py --class_names coco.names --data_format NHWC --weights_file yolov3.weights
- for YOLOv3-tiny: python3 convert_weights_pb.py --class_names coco.names --data_format NHWC --weights_file yolov3-tiny.weights --tiny
If you have YOLOv3 weights trained for an input image with the size different from 416 (320, 608 or your own), please provide the --size
key with the size of your image specified while running the converter. For example, run the following command for an image with size 608:
python3 convert_weights_pb.py --class_names coco.names --data_format NHWC --weights_file yolov3_608.weights --size 608
To solve the problems explained in the YOLOv3 architecture overview section, use the yolo_v3.json
or yolo_v3_tiny.json
(depending on a model) configuration file with custom operations located in the <OPENVINO_INSTALL_DIR>/deployment_tools/model_optimizer/extensions/front/tf repository.
It consists of several attributes:
[
{
"id": "TFYOLOV3",
"match_kind": "general",
"custom_attributes": {
"classes": 80,
"anchors": [10, 13, 16, 30, 33, 23, 30, 61, 62, 45, 59, 119, 116, 90, 156, 198, 373, 326],
"coords": 4,
"num": 9,
"masks":[[6, 7, 8], [3, 4, 5], [0, 1, 2]],
"entry_points": ["detector/yolo-v3/Reshape", "detector/yolo-v3/Reshape_4", "detector/yolo-v3/Reshape_8"]
}
}
]
where:
id
andmatch_kind
are parameters that you cannot change.custom_attributes
is a parameter that stores all the YOLOv3 specific attributes:classes
,coords
,num
, andmasks
are 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 useyolov3.cfg
oryolov3-tiny.cfg
configuration file from https://github.com/pjreddie/darknet/tree/master/cfg. Replace the default values incustom_attributes
with the parameters that follow the[yolo]
titles in the configuration file.anchors
is an optional parameter that is not used while inference of the model, but it used in a demo to parseRegion
layer outputentry_points
is a node name list to cut off the model and append the Region layer with custom attributes specified above.
To generate the IR of the YOLOv3 TensorFlow model, run:
python3 mo_tf.py
--input_model /path/to/yolo_v3.pb
--tensorflow_use_custom_operations_config $MO_ROOT/extensions/front/tf/yolo_v3.json
--batch 1
To generate the IR of the YOLOv3-tiny TensorFlow model, run:
python3 mo_tf.py
--input_model /path/to/yolo_v3_tiny.pb
--tensorflow_use_custom_operations_config $MO_ROOT/extensions/front/tf/yolo_v3_tiny.json
--batch 1
where:
--batch defines shape of model input. In the example, --batch is equal to 1, but you can also specify other integers larger than 1.
--tensorflow_use_custom_operations_config adds missing Region layers to the model. In the IR, the Region layer has name RegionYolo.