Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tdl-sdk-yolov8.md #80

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ sidebar_position: 21
## 下载预编译好的 cvimodel

```

git clone https://github.com/zwyzwm/YOLOv8-Object-Detection.git

```

## pc端交叉编译YOLO程序
Expand All @@ -31,9 +29,7 @@ Duo256M yolov8 代码位置:sample_yolov8.cpp
> - 下载 yolov8 官方仓库代码,地址如下: https://github.com/ultralytics

```

git clone https://github.com/ultralytics

```

> - 下载对应的 yolov8 模型文件
Expand All @@ -43,7 +39,6 @@ git clone https://github.com/ultralytics
```
cd ultralytics
wget https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n.pt

```

> - 导出 yolov8n.onnx 的模型
Expand All @@ -55,22 +50,18 @@ wget https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n.pt
激活(例如Python 3.8,torch2.0.1):

```

conda create -n py3.8 python==3.8.2
conda activate py3.8
python -m venv .venv
source .venv/bin/activate
pip3 install --upgrade pip
pip3 install torch==2.0.1

```

将 yolo_export/yolov8_export.py 代码复制到 yolov8 仓库

```

python3 yolov8_export.py --weights ./yolov8n.pt --img-size 640 640

```

提示:运行此命令时,出现类似`ModuleNotFoundError: No module named 'x'`错误,只需`pip install x`
Expand All @@ -90,12 +81,10 @@ python3 yolov8_export.py --weights ./yolov8n.pt --img-size 640 640
配置好工作环境后,在与本项目同级目录下创建一个model_yolov8n目录,将模型和图片文件放入其中。

```

mkdir model_yolov8n && cd model_yolov8n
cp ${REGRESSION_PATH}/yolov8n.onnx .
cp -rf ${REGRESSION_PATH}/dataset/COCO2017 .
cp -rf ${REGRESSION_PATH}/image .

```

提示:就是将yolov8n.onnx,COCO2017,image这三个文件复制到model_yolov8n
Expand All @@ -121,7 +110,6 @@ cp -rf ${REGRESSION_PATH}/image .


```

model_transform.py \
--model_name yolov8n \
--model_def yolov8n.onnx \
Expand All @@ -131,7 +119,6 @@ model_transform.py \
--keep_aspect_ratio \
--pixel_format rgb \
--mlir yolov8n.mlir

```

转换成 mlir 文件之后,会生成一个`yolov8n.mlir`文件。
Expand All @@ -141,26 +128,22 @@ model_transform.py \
量化成 INT8 模型前需要运行 calibration.py,得到校准表,输入数据的数量根据情况准备 100~1000 张左右,这里演示准备了 100 张 COCO2017 的图片:

```

run_calibration.py yolov8n.mlir \
--dataset ./COCO2017 \
--input_num 100 \
-o yolov8n_cali_table

```

用校准表生成 int8 对称 cvimodel:

```

model_deploy.py \
--mlir yolov8n.mlir \
--quant_input --quant_output \
--quantize INT8 \
--calibration_table yolov8n_cali_table \
--processor cv181x \
--model yolov8n_cv181x_int8_sym.cvimodel

```
编译完成后,会生成名为 yolov8n_cv181x_int8_sym.cvimodel 的文件。

Expand All @@ -174,13 +157,9 @@ model_deploy.py \
--calibration_table yolov8n_cali_table \
--processor cv181x \
--model yolov8n_cv181x_int8_asym.cvimodel

```
编译完成后,会生成名为 yolov8n_cv181x_int8_asym.cvimodel 的文件。




## 板端推理

将编译好的 sample_yolov8、cvimodel、要推理的 jpg 图片,拷贝到板端然后执行二进制程序:
Expand All @@ -192,13 +171,11 @@ model_deploy.py \
```
export LD_LIBRARY_PATH='/mnt/system/lib'
./sample_yolov8 ./yolov8n_cv181x_int8_sym.cvimodel 000000000632.jpg

```

效果如下:

```

[root@milkv-duo]~# ./sample_yolov8 ./yolov8n_cv181x_int8_sym.cvimodel 000000000
632.jpg
enter CVI_TDL_Get_YOLO_Preparam...
Expand All @@ -217,5 +194,4 @@ image read,width:640
image read,hidth:483
objnum:4
boxes=[[340.561,214.003,427.962,350.141,58,0.906066],[0.844345,279.573,401.244,477.67,59,0.894497],[181.399,124.6,241.393,227.863,58,0.680377],[245.295,229.886,349.774,318.173,56,0.562628],]

```