Introduction
This content takes YOLOv4, a public model, and shows how to convert it to a format called IR (.bin / .xml) for use in the OpenVINO™ toolkit. The YOLOv4 public model we will use is from the following URL
The contents of this document target Windows version 2020.4, which is the latest version at the time of writing (as of 9/29/2020).
The main steps are as follows
- Setup the TensowFlow 1.12.0 environment
- Dump the YOLOv4 TensowFlow model from the GitHub repository
- Convert to YOLOv4 frozen model (.pb)
- Convert YOLOv4 frozen model to IR
1. setting up the TensorFlow 1.12.0 environment
First of all, the environment of TensorFlow 1.12.0 is required, so we will introduce the procedure to set up the version 1.12.0.
1.1 Check the version of Tensorflow.
pip list
1.2 Uninstall Tensorflow if it is not 1.12.0.
pip uninstall tensorflow -y
TensorFlow is now uninstalled.
1.3 Install Tensorflow 1.12.0.
pip install tensorflow==1.12.0
TensorFlow-1.12.0 is now installed.
1.4 Check the version of Tensorflow just to be sure.
pip list
TensorFlow 1.12.0 was installed. 2.
2. dump the YOLOv4 TensowFlow model from the GitHub repository
First, we will show you how to dump a TensowFlow model from the GitHub repository (https://github.com/TNTWEN/OpenVINO-YOLOV4.git ).
2.1 Clone the YOLOv4 repository on GitHub
git clone https://github.com/TNTWEN/OpenVINO-YOLOV4.git
When the clone is complete, a directory like this will be created. (Here, we will proceed with the explanation assuming that you cloned it under C:\YV4. )
2.2 Navigate to the cloned directory (C:\YV4\OpenVINO-YOLOV4)
cd OpenVINO-YOLOV4
2.3 Download yolov4.weights from the following URL C:\YV4\OpenVINO-YOLOV4
Download is ready.
Reference URL:
- https://github.com/TNTWEN/OpenVINO-YOLOV4
- https://github.com/AlexeyAB/darknet
- https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v3_optimal/yolov4.weights
3. convert to YOLOv4 frozen model (.pb)
Run the Python library (converter) stored in the cloned YOLOv4 directory.
python convert_weights_pb.py --class_names cfg/coco.names --weights_file yolov4.weights --data_format NHWC
Once converted, the following message is generated.
We also confirmed that the file was generated. 4.
Converting YOLOv4 frozen model to IR
From here, we will use the Model Optimizer, a conversion Python library included in the OpenVINO™ toolkit.
Execute the following commands according to the data type to perform the conversion.
- Data type FP32
python C:\IntelSWTools\openvino\deployment_tools\model_optimizer\mo.py ^
--input_model frozen_darknet_yolov4_model.pb ^
-- transformations_config yolov4.json ^
--batch 1 ^
--reverse_input_channels ^
--data_type=FP32 ^
--output_dir C:\YV4\FP32 ^
--model_name yolov4
Once converted, the following message is generated.
We have also confirmed that the file has been generated.
- Data type FP16
python C:\IntelSWTools\openvino\deployment_tools\model_optimizer\mo.py ^
--input_model frozen_darknet_yolov4_model.pb ^
-- transformations_config yolov4.json ^
--batch 1 ^
--reverse_input_channels ^
--data_type=FP16 ^
--output_dir C:\YV4\FP16 ^
--model_name yolov4
Once converted, the following message is generated.
We also confirmed that the file was generated. 5.
5. summary
As you can see, the OpenVINO™ toolkit makes it easy to convert a publicly available generic model into a dedicated IR format. In addition to the generic models, Intel® offers a variety of pre-trained models that have already been trained by Intel®. These are available as commercially available pre-trained models, making it easy to build your own applications by combining the models you need.
The OpenVINO™ toolkit is also available to try on your own laptop. We invite you to try out the OpenVINO™ Toolkit on your own laptop and develop your own AI system.
Reference Links