YOLOX
This document describes how to run YOLOX on NPU.
Refer to Model Zoo Download for the example.
YOLOX Example Directory Structure:
$ tree ./
./
├── CMakeLists.txt
├── convert_model
│ ├── config_yml.py
│ ├── convert_model_env.sh
│ └── python
│ ├── coco_classes.py
│ ├── demo_utils.py
│ ├── sub_model.py
│ ├── visualize.py
│ └── yolox_sim.py
├── figures
│ ├── output_yolox.png
│ └── yolox_rt.png
├── main.cpp
├── model
│ └── bus.jpg
├── model_config.h
├── README.md
├── yolox_postprocess.cpp
└── yolox_preprocess.cpp
Model Conversion
Download Model
cd convert_model/
wget https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/yolox_s.onnx
Or download the modified model, click to download yolox_s_sim.onnx.
Then move to the convert_model/ directory.
Prune Model
If you downloaded the already converted model, you can skip model pruning.
cd python/
python3 sub_model.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/yolox/convert_model/
./pegasus_import.sh yolox_s_sim
./pegasus_quantize.sh yolox_s_sim uint8 12
- A733
- T527
./pegasus_export_ovx_nbg.sh yolox_s_sim uint8 a733
./pegasus_export_ovx_nbg.sh yolox_s_sim 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/yolox/
- 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 yolox_demo_linux_a733/
chmod +x ./yolox_demo_a733
./yolox_demo_a733 -nb model/yolox_s_sim_uint8_a733.nb -i model/bus.jpg
The running result is as follows:
$ ./yolox_demo_a733 -nb model/yolox_s_sim_uint8_a733.nb -i model/bus.jpg
model_file=model/yolox_s_sim_uint8_a733.nb, input=model/bus.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 85 1, data_format=0, name=uid_20000_sub_uid_1_out_0, none-quant
output 1 dim 40 40 85 1, data_format=0, name=uid_20001_sub_uid_1_out_0, none-quant
output 2 dim 20 20 85 1, data_format=0, name=uid_20002_sub_uid_1_out_0, none-quant
nbg name=model/yolox_s_sim_uint8_a733.nb, size: 7058512.
create network 0: 17292 us.
prepare network: 7783 us.
buffer ptr: 0x24831600, buffer size: 1228800
Original image size: 640x640
YOLOX preprocess completed: model/bus.jpg -> 640x640, buffer size: 1228800
feed input cost: 11464 us.
network: 0, loop count: 1
run time for this network 0: 30120 us.
detection num: 5
5: 93%, [ 85, 136, 555, 433], bus
0: 89%, [ 113, 243, 199, 524], person
0: 86%, [ 475, 239, 560, 520], person
0: 89%, [ 213, 243, 283, 506], person
0: 56%, [ 79, 328, 121, 515], person
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 | yolox_s | 640×640 | 17.3 ms | 7.8 ms | 30.1 ms | 55.2 ms | 33.2 FPS |
cd yolox_demo_linux_t527/
chmod +x ./yolox_demo_t527
./yolox_demo_t527 -nb model/yolox_s_sim_uint8_t527.nb -i model/bus.jpg
The running result is as follows:
$ ./yolox_demo_t527 -nb model/yolox_s_sim_uint8_t527.nb -i model/bus.jpg
model_file=model/yolox_s_sim_uint8_t527.nb, input=model/bus.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 85 1, data_format=0, name=uid_20000_sub_uid_1_out_0, none-quant
output 1 dim 40 40 85 1, data_format=0, name=uid_20001_sub_uid_1_out_0, none-quant
output 2 dim 20 20 85 1, data_format=0, name=uid_20002_sub_uid_1_out_0, none-quant
nbg name=model/yolox_s_sim_uint8_t527.nb, size: 9132672.
create network 0: 25385 us.
prepare network: 18164 us.
buffer ptr: 0x116c6600, buffer size: 1228800
Original image size: 640x640
YOLOX preprocess completed: model/bus.jpg -> 640x640, buffer size: 1228800
feed input cost: 62033 us.
network: 0, loop count: 1
run time for this network 0: 73697 us.
detection num: 5
5: 93%, [ 98, 137, 550, 435], bus
0: 89%, [ 107, 239, 210, 533], person
0: 87%, [ 477, 239, 560, 519], person
0: 89%, [ 214, 243, 283, 506], person
0: 58%, [ 79, 329, 120, 516], person
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 | yolox_s | 640×640 | 25.4 ms | 18.2 ms | 73.7 ms | 117.3 ms | 13.6 FPS |