/YOLOv7_OpenVINO_cpp-python

This repository will demostrate how to deploy a offical YOLOv7 pre-trained model with OpenVINO runtime api

Primary LanguageC++

YOLOv7_OpenVINO

This repository will demostrate how to deploy a offical YOLOv7 pre-trained model with OpenVINO runtime api

1. Install requirements

Python

  $ pip install -r python/requirements.txt

C++ (Ubuntu)

Please follow the Guides to install OpenVINO and OpenCV

2. Prepare the model

Download YOLOv7 pre-trained weight from YOLOv7

3. Export the ONNX model and convert it to OpenVINO IR

  $ git clone git@github.com:WongKinYiu/yolov7.git
  $ cd yolov7/models
  $ python export.py --weights yolov7.pt
  $ mo -m yolov7.onnx --compress_to_fp16

4. Run inference

The input image can be found in YOLOv7's repository

Python

 $ python python/image.py -m yolov7.xml -i data/horse.jpg -d "CPU" -p False

You can also try running the code with Preprocessing API for performance optimization.

 $ python python/image.py -m yolov7.xml -i data/horse.jpg -p
  • -i = path to image or video source;
  • -m = Path to IR .xml or .onnx file;
  • -d = Device name, e.g "CPU";
  • -p = with/without preprocessing api
  • -bs = Batch size;
  • -n = number of infer requests;
  • -g = with/without grid in model

C++ (Ubuntu)

Compile the source code

  $ cd cpp
  $ mkdir build && cd build
  $ source '~/intel/openvino_2022.1.0.643/bin/setupvars.sh'
  $ cmake ..
  $ make

You can also uncomment the code in CMakeLists.txt to trigger Preprocessing API for performance optimization.

Run inference

 $ yolov7 yolov7.xml data/horses.jpg 'CPU' false

5. Results

horse_res

6. Run with webcam

You can also run the sample with webcam for real-time detection

$ python python/webcam.py -m yolov7.xml -i 0

Tips: you can switch the device name to "GPU" to improve the performance.

7. Further optimization

Try this notebook (yolov7-optimization) and quantize your YOLOv7 model to INT8.