YOLOv8 Seg
This document describes how to run YOLOv8 Seg on NPU.
Refer to Model Zoo Download for the example.
YOLOv8 Seg Example Directory Structure:
$ tree ./
./
├── CMakeLists.txt
├── convert_model
│ ├── config_yml.py
│ ├── convert_model_env.sh
│ ├── python
│ │ ├── onnx_extract.py
│ │ └── yolov8s-seg_640.txt
│ └── yolov8s-seg_10.txt
├── figures
│ ├── diff_img.png
│ └── out_yolov8_seg.png
├── main.cpp
├── model
│ ├── bus.jpg
│ └── dog.jpg
├── model_config.h
├── README.md
├── yolov8_seg_10_post.cpp
└── yolov8_seg_10_pre.cpp
Model Conversion
Configure Virtual Environment
python -m venv .venv && source .venv/bin/activate
pip install ultralytics onnxsim
Export ONNX Model
cd convert_model/python/
yolo export model=yolov8s-seg.pt format=onnx dynamic=True opset=11
Fixed Shape
python3 -m onnxsim yolov8s-seg.onnx yolov8s-seg_640.onnx --input-shape=1,3,640,640
Prune Model
python3 onnx_extract.py
cd ..
Create Symlink for Conversion Script
./convert_model_env.sh
Model Import/Quantization/Conversion
You need to enter the container development environment first. Refer to the Create Container section in Model Zoo Download.
Different platforms use corresponding Docker images:
- A733: ubuntu-npu:v2.0.10.1
- T527: ubuntu-npu:v1.8.11
docker exec -it model-zoo /bin/bash
After entering the container, navigate to the corresponding directory and run the script.
cd /workspace/examples/yolov8_seg/convert_model/
./pegasus_import.sh yolov8s-seg_10
./pegasus_quantize.sh yolov8s-seg_10 uint8 12
- A733
- T527
./pegasus_export_ovx_nbg.sh yolov8s-seg_10 uint8 a733
./pegasus_export_ovx_nbg.sh yolov8s-seg_10 uint8 t527
The exported model files are stored in the ../model directory.
Compile Example
Now you can compile the example. First exit the container, then execute the following command to compile the example.
First, you need to configure third-party libraries and cross-compilation toolchain.
You can skip this step if you have already configured third-party libraries and cross-compilation toolchain in other examples.
cd ../../../3rdparty/opencv/
unzip opencv-4.9.0-aarch64-linux-sunxi-glibc.zip
cd ../../0-toolchains/
You need to manually download via this link first, then place it in 0-toolchains/ before executing the following command:
tar -xvf gcc-arm-10.2-2020.11-x86_64-aarch64-none-linux-gnu.tar.xz
cd ../examples/yolov8_seg/
- A733
- T527
../build_linux.sh -t a733 -s debian11
../build_linux.sh -t t527 -s debian11
Model Deployment
After compilation, the example will be installed in the install directory. You can use scp to transfer it to the board.
Configure NPU Driver
You can skip this step if you have already configured NPU driver in other examples.
Transfer the driver library to the board's lib directory via scp.
- A733 corresponds to the common/lib_linux_aarch64/A733 directory
- T527 corresponds to the common/lib_linux_aarch64/T527 directory
Then execute the following command to export to environment variables.
echo 'export LD_LIBRARY_PATH=$HOME/lib:$LD_LIBRARY_PATH' >> ~/.bashrc
Run Example
After configuring the driver, you can run the example.
For T527 platform, you need to first enable NPU by referring to the A5E's "Enable NPU on Board" documentation, then use the following command to grant the current user permission to use /dev/vipcore.
sudo chmod 777 /dev/vipcore
- A733
- T527
cd yolov8_seg_demo_linux_a733/
chmod +x ./yolov8_seg_demo_a733
./yolov8_seg_demo_a733 -nb model/yolov8s-seg_10_uint8_a733.nb -i model/dog.jpg
The running result is as follows:
$ ./yolov8_seg_demo_a733 -nb model/yolov8s-seg_10_uint8_a733.nb -i model/dog.jpg
model_file=model/yolov8s-seg_10_uint8_a733.nb, input=model/dog.jpg, loop_count=1, malloc_mbyte=10
VIPLite driver software version 2.0.3.2-AW-2024-08-30
input 0 dim 3 640 640 1, data_format=2, quant_format=0, name=input/output[0], none-quant
output 0 dim 80 80 64 1, data_format=0, name=uid_19_out_0b_uid_1_out_0, none-quant
output 1 dim 80 80 80 1, data_format=0, name=uid_18_out_0b_uid_1_out_0, none-quant
output 2 dim 80 80 32 1, data_format=0, name=uid_17_out_0b_uid_1_out_0, none-quant
output 3 dim 40 40 64 1, data_format=0, name=uid_16_out_0b_uid_1_out_0, none-quant
output 4 dim 40 40 80 1, data_format=0, name=uid_15_out_0b_uid_1_out_0, none-quant
output 5 dim 40 40 32 1, data_format=0, name=uid_14_out_0b_uid_1_out_0, none-quant
output 6 dim 20 20 64 1, data_format=0, name=uid_13_out_0b_uid_1_out_0, none-quant
output 7 dim 20 20 80 1, data_format=0, name=uid_12_out_0b_uid_1_out_0, none-quant
output 8 dim 20 20 32 1, data_format=0, name=uid_11_out_0b_uid_1_out_0, none-quant
output 9 dim 160 160 32 1, data_format=0, name=uid_20009_sub_uid_1_out_0, none-quant
nbg name=model/yolov8s-seg_10_uint8_a733.nb, size: 8089336.
create network 0: 21684 us.
prepare network: 4881 us.
buffer ptr: 0x127ba600, buffer size: 1228800
network: 0, loop count: 1
run time for this network 0: 38144 us.
output 0, ptr 0x128e6780, size 409600.
output 1, ptr 0x12a76800, size 512000.
output 2, ptr 0x12c6a880, size 204800.
output 3, ptr 0x12d32900, size 102400.
output 4, ptr 0x12d969c0, size 128000.
output 5, ptr 0x12e13a40, size 51200.
output 6, ptr 0x12e45ac0, size 25600.
output 7, ptr 0x12e5eb40, size 32000.
output 8, ptr 0x12e7e000, size 12800.
output 9, ptr 0x12e8a880, size 819200.
post process time : 12 ms
detection num: 3
1: 89%, [ 126, 133, 568, 425], bicycle
16: 96%, [ 131, 220, 310, 541], dog
7: 65%, [ 470, 73, 688, 171], truck
destroy npu finished.
~NpuUint.
This performance data only calculates the time consumption of model inference. Unless otherwise specified, it does not include the time consumption of pre-processing and post-processing.
| SoC | NPU | Model | Input Resolution | Network Creation Time | Network Preparation Time | Single Frame Inference Time | Post-processing Time | Total Time | Frame Rate |
|---|---|---|---|---|---|---|---|---|---|
| Allwinner A733 | Vivante VIP9000 | yolov8s-seg | 640×640 | 21.7 ms | 4.9 ms | 38.1 ms | 12 ms | 76.7 ms | 26.3 FPS |
cd yolov8_seg_demo_linux_t527/
chmod +x ./yolov8_seg_demo_t527
./yolov8_seg_demo_t527 -nb model/yolov8s-seg_10_uint8_t527.nb -i model/dog.jpg
The running result is as follows:
$ ./yolov8_seg_demo_t527 -nb model/yolov8s-seg_10_uint8_t527.nb -i model/dog.jpg
model_file=model/yolov8s-seg_10_uint8_t527.nb, input=model/dog.jpg, loop_count=1, malloc_mbyte=10
VIPLite driver software version 1.13.0.0-AW-2023-10-19
input 0 dim 3 640 640 1, data_format=2, quant_format=0, name=input[0], none-quant
output 0 dim 80 80 64 1, data_format=0, name=uid_20000_sub_uid_1_out_0, none-quant
output 1 dim 80 80 80 1, data_format=0, name=uid_20001_sub_uid_1_out_0, none-quant
output 2 dim 80 80 32 1, data_format=0, name=uid_20002_sub_uid_1_out_0, none-quant
output 3 dim 40 40 64 1, data_format=0, name=uid_20003_sub_uid_1_out_0, none-quant
output 4 dim 40 40 80 1, data_format=0, name=uid_20004_sub_uid_1_out_0, none-quant
output 5 dim 40 40 32 1, data_format=0, name=uid_20005_sub_uid_1_out_0, none-quant
output 6 dim 20 20 64 1, data_format=0, name=uid_20006_sub_uid_1_out_0, none-quant
output 7 dim 20 20 80 1, data_format=0, name=uid_20007_sub_uid_1_out_0, none-quant
output 8 dim 20 20 32 1, data_format=0, name=uid_20008_sub_uid_1_out_0, none-quant
output 9 dim 160 160 32 1, data_format=0, name=uid_20009_sub_uid_1_out_0, none-quant
nbg name=model/yolov8s-seg_10_uint8_t527.nb, size: 11076992.
create network 0: 34337 us.
prepare network: 22250 us.
buffer ptr: 0x10312600, buffer size: 1228800
network: 0, loop count: 1
run time for this network 0: 88575 us.
output 0, ptr 0x1043e740, size 409600.
output 1, ptr 0x105ce7c0, size 512000.
output 2, ptr 0x107c2880, size 204800.
output 3, ptr 0x1088a900, size 102400.
output 4, ptr 0x108ee980, size 128000.
output 5, ptr 0x1096ba00, size 51200.
output 6, ptr 0x1099dac0, size 25600.
output 7, ptr 0x109b6b40, size 32000.
output 8, ptr 0x109d5fc0, size 12800.
output 9, ptr 0x109e2840, size 819200.
post process time : 54 ms
detection num: 3
1: 89%, [ 126, 133, 568, 426], bicycle
16: 95%, [ 131, 220, 310, 541], dog
7: 66%, [ 470, 73, 688, 170], truck
destroy npu finished.
~NpuUint.
This performance data only calculates the time consumption of model inference. Unless otherwise specified, it does not include the time consumption of pre-processing and post-processing.
| SoC | NPU | Model | Input Resolution | Network Creation Time | Network Preparation Time | Single Frame Inference Time | Post-processing Time | Total Time | Frame Rate |
|---|---|---|---|---|---|---|---|---|---|
| Allwinner T527 | Vivante VIP9000 | yolov8s-seg | 640×640 | 34.3 ms | 22.3 ms | 88.6 ms | 54.0 ms | 199.2 ms | 11.3 FPS |