Skip to content

Latest commit

 

History

History
224 lines (142 loc) · 5.6 KB

README.md

File metadata and controls

224 lines (142 loc) · 5.6 KB

yolov7

Table of contents

1. Description

The model used in this example comes from the following open source projects:

https://github.com/airockchip/yolov7

2. Current Support Platform

RK3566, RK3568, RK3588, RK3562

3. Pretrained Model

Download link:

./yolov7-tiny.onnx
./yolov7.onnx

Download with shell command:

cd model
./download_model.sh

4. Convert to RKNN

Usage:

cd python
python convert.py <onnx_model> <TARGET_PLATFORM> <dtype(optional)> <output_rknn_path(optional)>

# such as: 
python convert.py ../model/yolov7-tiny.onnx rk3588
# output model will be saved as ../model/yolov7.rknn

Description:

  • <onnx_model>: Specify ONNX model path.
  • <TARGET_PLATFORM>: Specify NPU platform name. Support Platform refer [here](#2 Current Support Platform).
  • <dtype>(optional): Specify as i8 or fp. i8 for doing quantization, fp for no quantization. Default is i8.
  • <output_rknn_path>(optional): Specify save path for the RKNN model, default save in the same directory as ONNX model with name yolov7.rknn

5. Python Demo

Usage:

cd python
# Inference with PyTorch model or ONNX model
python yolov7.py --model_path <pt_model/onnx_model> --img_show

# Inference with RKNN model
python yolov7.py --model_path <rknn_model> --target <TARGET_PLATFORM> --img_show

Description:

  • <TARGET_PLATFORM>: Specify NPU platform name. Support Platform refer [here](#2 Current Support Platform).

  • <pt_model / onnx_model / rknn_model>: Specify the model path.

6. Android Demo

6.1 Compile and Build

Usage:

# go back to the rknn_model_zoo root directory
cd ../../
export ANDROID_NDK_PATH=<android_ndk_path>

./build-android.sh -t <TARGET_PLATFORM> -a <ARCH> -d yolov7

# such as 
./build-android.sh -t rk3588 -a arm64-v8a -d yolov7

Description:

  • <android_ndk_path>: Specify Android NDK path.
  • <TARGET_PLATFORM>: Specify NPU platform name. Support Platform refer [here](#2 Current Support Platform).
  • <ARCH>: Specify device system architecture. To query device architecture, refer to the following command:
     # Query architecture. For Android, ['arm64-v8a' or 'armeabi-v7a'] should shown in log.
     adb shell cat /proc/version

6.2 Push demo files to device

With device connected via USB port, push demo files to devices:

adb root
adb remount
adb push install/<TARGET_PLATFORM>_android_<ARCH>/rknn_yolov7_demo/ /data/

6.3 Run demo

adb shell
cd /data/rknn_yolov7_demo

export LD_LIBRARY_PATH=./lib
./rknn_yolov7_demo model/yolov7.rknn model/bus.jpg
  • After running, the result was saved as out.png. To check the result on host PC, pull back result referring to the following command:

    adb pull /data/rknn_yolov7_demo/out.png
  • Output result refer Expected Results.

7. Linux Demo

7.1 Compile and Build

Usage:

# go back to the rknn_model_zoo root directory
cd ../../

# if GCC_COMPILER not found while building, please set GCC_COMPILER path
(optional)export GCC_COMPILER=<GCC_COMPILER_PATH>

./build-linux.sh -t <TARGET_PLATFORM> -a <ARCH> -d yolov7

# such as 
./build-linux.sh -t rk3588 -a aarch64 -d yolov7

Description:

  • <GCC_COMPILER_PATH>: Specified as GCC_COMPILER path.

  • <TARGET_PLATFORM> : Specify NPU platform name. Support Platform refer [here](#2 Current Support Platform).

  • <ARCH>: Specify device system architecture. To query device architecture, refer to the following command:

    # Query architecture. For Linux, ['aarch64' or 'armhf'] should shown in log.
    adb shell cat /proc/version

7.2 Push demo files to device

  • If device connected via USB port, push demo files to devices:
adb push install/<TARGET_PLATFORM>_linux_<ARCH>/rknn_yolov7_demo/ /userdata/
  • For other boards, use scp or other approaches to push all files under install/<TARGET_PLATFORM>_linux_<ARCH>/rknn_yolov7_demo/ to userdata.

7.3 Run demo

adb shell
cd /userdata/rknn_yolov7_demo

export LD_LIBRARY_PATH=./lib
./rknn_yolov7_demo model/yolov7.rknn model/bus.jpg
  • After running, the result was saved as out.png. To check the result on host PC, pull back result referring to the following command:

    adb pull /userdata/rknn_yolov7_demo/out.png
    
  • Output result refer Expected Results.

8. Expected Results

This example will print the labels and corresponding scores of the test image detect results, as follows:

person @ (212 241 285 511) 0.886
bus @ (86 134 540 444) 0.855
person @ (476 237 561 519) 0.835
person @ (112 234 218 531) 0.835
person @ (79 330 124 524) 0.346

  • Note: Different platforms, different versions of tools and drivers may have slightly different results.