/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

1.1 Python

  $ pip install -r python/requirements.txt

1.2 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
  $ pip install -r requirements
  $ python export.py --weights yolov7.pt
  $ ovc yolov7.onnx

4. Run inference

The input image can be found in YOLOv7's repository

4.1 Python

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

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

 $ python python/image.py -m path_to/yolov7.xml -i data/horse.jpg -d "CPU" -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;

4.2 C++ (Ubuntu)

Compile the source code

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

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

Run inference

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

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 path_to/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.