This is my fourth day of the August Challenge

Software and Hardware Environment

  • Ubuntu 18.04 64 – bit
  • 3.341 openvino_2020.
  • Yolov5 4.0

What is openvino

Openvino is a solution for deep learning deployment on Intel hardware platforms, Windows, Linux, and macOS.

Set up the OpenVino environment

Download address: software.intel.com/content/www…

After downloading, unzip it and go to the directory

Tar XVF l_openvino_toolkit_p_2020.3.341.tgz CD l_openvino_toolkit_p_2020.3.341Copy the code

Execute the script and start the installation as prompted

/ install_gui. sh sudo./install.sh sudoCopy the code

Press Enter to continue

Option 2, do not agree to collect my information

Press Enter to continue

Agree and start installation

Press Enter to continue

At this point, the installation is complete

Next, test whether the installation was successful

cd /opt/intel/openvino/deployment_tools/demo ./demo_security_barrier_camera.sh ./demo_security_barrier_camera.sh -d GPU(Testing the GPU environment)Copy the code

This indicates that the OpenVino environment has been installed successfully.

It is important to note that since the script has already set up the environment for us during the installation process, we do not need to do any setup when we go to test. But the next time we boot up, or open a new terminal, we need to reset the environment to execute

source /opt/intel/openvino/bin/setupvars.sh
Copy the code

Or write the above command directly to ~/.bashrc, so you don’t have to manually type each time.

/opt/ Intel openVino and Openvino_2020.3.3412 directories are the same. Openvino is a soft link file.

Pt turn onnx

First prepare for dependency

pip install onnx coremltools networkx defusedxml
Copy the code

Because the current OpenVino version has problems supporting onnX Opset after version 11, it is necessary to modify the file Model/export-. py and change the original opset_version from 12 to 10, as follows

torch.onnx.export(model, img, f, verbose=False, opset_version=10, input_names=['images'],
                    output_names=['classes', 'boxes'] if y is None else ['output'])
Copy the code

Next, you can convert the PT model of yoloV5 into onNX format, using its own yolov5s.pt model for testing

python models/export.py --weights weights/yolov5s.pt --img-size 640 --batch-size 1
Copy the code

When the conversion is complete, yolov5s.onnx is generated under the Weights folder

Turn onnx ir

Ir is Intermediate Representation. Openvino’s Model Optimizer converts a given Model into a standard IR format and optimizes it.

Using openVino’s own script, you can complete the transformation from.onnx to.bin and.xml

mo.py --input_model weights/yolov5s.onnx
Copy the code

You can see that yolov5s.bin and yolov5s.xml are generated so far

Openvino test

Here use c++ language to write the test program, download address: github.com/fb029ed/yol… Thank you very much for sharing

cd yolov5_cpp_openvino/demo
mkdir build
cmake ..
make
./detect_test
Copy the code

You need to copy the yolov5s.bin, yolov5s. XML and a test image to the res directory and rename the image to bus.jpg

The resources

  • Software.intel.com/content/www…
  • Github.com/violet17/yo…
  • Github.com/fb029ed/yol…