Doc for version ddk-3.4.7.7
Download the YOLOv7 official code WongKinYiu/yolov7
$ git clone https://github.com/WongKinYiu/yolov7
Refer README.md
to create and train a YOLOv7 tiny model.
Follow Docker official documentation to install Docker: Install Docker Engine on Ubuntu.
Follow the script below to get Docker image:
docker pull numbqq/npu-vim4
Download The conversion tool from khadas/vim4_npu_sdk.
$ git lfs install $ git lfs clone https://gitlab.com/khadas/vim4_npu_sdk.git $ cd vim4_npu_sdk $ ls adla-toolkit-binary adla-toolkit-binary-3.1.7.4 convert-in-docker.sh Dockerfile docs README.md
adla-toolkit-binary/docs
- SDK documentationsadla-toolkit-binary/bin
- SDK tools required for model conversionadla-toolkit-binary/demo
- Conversion examplesIf your kernel is older than 241129, please use version before tag ddk-3.4.7.7.
After training the model, modify yolov7/models/yolo.py
as follows.
diff --git a/models/yolo.py b/models/yolo.py index 95a019c..98ae95c 100644 --- a/models/yolo.py +++ b/models/yolo.py @@ -144,7 +144,10 @@ class IDetect(nn.Module): for i in range(self.nl): x[i] = self.m[i](x[i]) # conv bs, _, ny, nx = x[i].shape # x(bs,255,20,20) to x(bs,3,20,20,85) - x[i] = x[i].view(bs, self.na, self.no, ny, nx).permute(0, 1, 3, 4, 2).contiguous() if not self.training: # inference if self.grid[i].shape[2:4] != x[i].shape[2:4]:
yolo.py has many forward. Right place is class IDetect function fuseforward.
Then, run export.py
to convert the model to ONNX.
$ python export.py
Enter vim4_npu_sdk/demo
and modify convert_adla.sh
as follows.
#!/bin/bash ACUITY_PATH=../bin/ #ACUITY_PATH=../python/tvm/ adla_convert=${ACUITY_PATH}adla_convert if [ ! -e "$adla_convert" ]; then adla_convert=${ACUITY_PATH}adla_convert.py fi $adla_convert --model-type onnx \ --model ./model_source/yolov7_tiny/yolov7_tiny.onnx \ --inputs "images" \ --input-shapes "3,640,640" \ --dtypes "float32" \ --quantize-dtype int8 --outdir onnx_output \ --channel-mean-value "0,0,0,255" \ --inference-input-type "float32" \ --inference-output-type "float32" \ --source-file dataset.txt \ --batch-size 1 --target-platform PRODUCT_PID0XA003
Run convert_adla.sh
to generate the VIM4 model. The converted model is xxx.adla
in onnx_output
.
$ bash convert_adla.sh
Clone the source code khadas/vim4_npu_applications.
$ git clone https://github.com/khadas/vim4_npu_applications
If your kernel is older than 241129, please use version before tag ddk-3.4.7.7.
$ sudo apt update $ sudo apt install libopencv-dev python3-opencv cmake
Put yolov7_tiny_int8.adla
in vim4_npu_applications/yolov7_tiny/data/
.
# Compile $ cd vim4_npu_applications/yolov7_tiny $ mkdir build $ cd build $ cmake .. $ make # Run $ ./yolov7_tiny -m ../data/yolov7_tiny_int8.adla -p ../data/horses.jpg
Put yolov7_tiny_int8.adla
in vim4_npu_applications/yolov7_tiny_cap/data/
.
# Compile $ cd vim4_npu_applications/yolov7_tiny_cap $ mkdir build $ cd build $ cmake .. $ make # Run $ ./yolov7_tiny_cap -m ../data/yolov7_tiny_int8.adla -d 0
0
is the camera device index.
If your YOLOv7-tiny model classes are not the same as COCO, please change data/coco_80_labels_list.txt
and the OBJ_CLASS_NUM
in include/postprocess.h
.