RetinaFace
This document describes how to run RetinaFace on NPU.
Refer to Model Zoo Download for the example.
RetinaFace Example Directory Structure:
$ tree ./
./
├── CMakeLists.txt
├── convert_model
│ ├── config_yml.py
│ ├── convert_model_env.sh
│ └── Retinaface_resnet50_320.txt
├── figures
│ └── out_retinaface.png
├── main.cpp
├── model
│ └── test.jpg
├── model_config.h
├── README.md
├── retinaface_post.cpp
└── retinaface_pre.cpp
Model Conversion
Export ONNX Model
Click to download Resnet50_Final.pth.
Download ONNX Model
You can download the modified model.
Click to download Retinaface_resnet50_320.onnx.
Click to download Retinaface_mobilenet0.25_320.onnx.
Then move to the convert_model/ directory.
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/retinaface/convert_model/
./pegasus_import.sh Retinaface_resnet50_320
./pegasus_quantize.sh Retinaface_resnet50_320 uint8 10
- A733
- T527
./pegasus_export_ovx_nbg.sh Retinaface_resnet50_320 uint8 a733
./pegasus_export_ovx_nbg.sh Retinaface_resnet50_320 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/retinaface/
- 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 retinaface_demo_linux_a733/
chmod +x ./retinaface_demo_a733
./retinaface_demo_a733 -nb model/Retinaface_resnet50_320_uint8_a733.nb -i model/test.jpg
The running result is as follows:
$ ./retinaface_demo_a733 -nb model/Retinaface_resnet50_320_uint8_a733.nb -i model/test.jpg
model_file=model/Retinaface_resnet50_320_uint8_a733.nb, input=model/test.jpg, loop_count=1, malloc_mbyte=10
VIPLite driver software version 2.0.3.2-AW-2024-08-30
input 0 dim 3 320 320 1, data_format=2, quant_format=0, name=input/output[0], none-quant
output 0 dim 4 4200 1 0, data_format=0, name=uid_20000_sub_uid_1_out_0, none-quant
output 1 dim 2 4200 1 0, data_format=0, name=uid_20001_sub_uid_1_out_0, none-quant
output 2 dim 10 4200 1 0, data_format=0, name=uid_20002_sub_uid_1_out_0, none-quant
nbg name=model/Retinaface_resnet50_320_uint8_a733.nb, size: 19056048.
create network 0: 20781 us.
prepare network: 2285 us.
buffer ptr: 0x25971380, buffer size: 307200
network: 0, loop count: 1
run time for this network 0: 18564 us.
output 0, ptr 0x259d7240, size 16800.
output 1, ptr 0x259e5240, size 8400.
output 2, ptr 0x259f3240, size 42000.
post process time : 1 ms
detection num: 1
100%, [ 244, 45, 363, 208], face
275.10 113.49
328.03 112.26
300.95 147.94
277.57 166.40
326.80 165.17
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 | Retinaface_resnet50 | 320×320 | 20.8 ms | 2.3 ms | 15.7 ms | 0.0 ms | 38.8 ms | 63.7 FPS |
cd retinaface_demo_linux_t527/
chmod +x ./retinaface_demo_t527
./retinaface_demo_t527 -nb model/Retinaface_resnet50_320_uint8_t527.nb -i model/test.jpg
The running result is as follows:
$ ./retinaface_demo_t527 -nb model/Retinaface_resnet50_320_uint8_t527.nb -i model/test.jpg
model_file=model/Retinaface_resnet50_320_uint8_t527.nb, input=model/test.jpg, loop_count=1, malloc_mbyte=10
VIPLite driver software version 1.13.0.0-AW-2023-10-19
input 0 dim 3 320 320 1, data_format=2, quant_format=0, name=input[0], none-quant
output 0 dim 4 4200 1 0, data_format=0, name=uid_20000_sub_uid_1_out_0, none-quant
output 1 dim 2 4200 1 0, data_format=0, name=uid_20001_sub_uid_1_out_0, none-quant
output 2 dim 10 4200 1 0, data_format=0, name=uid_20002_sub_uid_1_out_0, none-quant
nbg name=model/Retinaface_resnet50_320_uint8_t527.nb, size: 18714688.
create network 0: 27602 us.
prepare network: 5276 us.
buffer ptr: 0x23c57380, buffer size: 307200
network: 0, loop count: 1
run time for this network 0: 30483 us.
output 0, ptr 0x23ca2440, size 16800.
output 1, ptr 0x23cb2b40, size 8400.
output 2, ptr 0x23cbaf40, size 42000.
post process time : 1 ms
detection num: 1
100%, [ 244, 45, 363, 208], face
275.10 113.49
328.03 112.26
300.95 147.94
277.57 166.40
326.80 165.17
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 | Retinaface_resnet50 | 320×320 | 27.6 ms | 5.3 ms | 30.5 ms | 1.0 ms | 64.4 ms | 32.8 FPS |