MobileNetV2
This document describes how to run MobileNetV2 on NPU.
Refer to Model Zoo Download for the example.
MobileNetV2 Example Directory Structure:
$ tree ./
./
├── class_post.cpp
├── class_pre.cpp
├── CMakeLists.txt
├── convert_model
│ ├── config_yml.py
│ ├── convert_model_env.sh
│ └── mobilenetv2-12.onnx
├── label.h
├── main.cpp
├── model
│ ├── 1.jpg
│ └── mobilenetv2-12_pcq_t527.nb
└── README.md
Model Conversion
Download Model
The model already exists in the directory, no download needed.
Create Symlink for Conversion Script
cd convert_model/
./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/mobilenetv2/convert_model/
./pegasus_import.sh mobilenetv2-12
./pegasus_quantize.sh mobilenetv2-12 pcq 10
- A733
- T527
./pegasus_export_ovx_nbg.sh mobilenetv2-12 pcq a733
./pegasus_export_ovx_nbg.sh mobilenetv2-12 pcq 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/mobilenetv2/
- 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 mobilenetv2_demo_linux_a733/
chmod +x ./mobilenetv2_demo_a733
./mobilenetv2_demo_a733 -nb model/mobilenetv2-12_pcq_a733.nb -i model/1.jpg
The running result is as follows:
$ ./mobilenetv2_demo_a733 -nb model/mobilenetv2-12_pcq_a733.nb -i model/1.jpg
model_file=model/mobilenetv2-12_pcq_a733.nb, input=model/1.jpg, loop_count=1, malloc_mbyte=10
VIPLite driver software version 2.0.3.2-AW-2024-08-30
input 0 dim 3 224 224 1, data_format=2, quant_format=0, name=input/output[0], none-quant
output 0 dim 1000 1 0 0, data_format=0, name=uid_20000_sub_uid_1_out_0, none-quant
nbg name=model/mobilenetv2-12_pcq_a733.nb, size: 3617080.
create network 0: 6194 us.
prepare network: 1134 us.
network: 0, loop count: 1
run time for this network 0: 1792 us.
class_postprocess.cpp run.
========== top5 ==========
class id: 281, prob: 15.055555, label: tabby, tabby cat
class id: 285, prob: 13.879630, label: Egyptian cat
class id: 287, prob: 11.990741, label: lynx, catamount
class id: 282, prob: 8.842592, label: tiger cat
class id: 631, prob: 4.837963, label: grey fox
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 | mobilenetv2 | 224×224 | 6.2 ms | 1.5 ms | 2.0 ms | 9.7 ms | 500.0 FPS |
cd mobilenetv2_demo_linux_t527/
chmod +x ./mobilenetv2_demo_t527
./mobilenetv2_demo_t527 -nb model/mobilenetv2-12_pcq_t527.nb -i model/1.jpg
The running result is as follows:
$ ./mobilenetv2_demo_t527 -nb model/mobilenetv2-12_pcq_t527.nb -i model/1.jpg
model_file=model/mobilenetv2-12_pcq_t527.nb, input=model/1.jpg, loop_count=1, malloc_mbyte=10
VIPLite driver software version 1.13.0.0-AW-2023-10-19
input 0 dim 3 224 224 1, data_format=2, quant_format=0, name=input[0], none-quant
output 0 dim 1000 1 0 0, data_format=0, name=uid_20000_sub_uid_1_out_0, none-quant
nbg name=model/mobilenetv2-12_pcq_t527.nb, size: 3515008.
create network 0: 6479 us.
prepare network: 1872 us.
network: 0, loop count: 1
run time for this network 0: 3127 us.
class_postprocess.cpp run.
========== top5 ==========
class id: 281, prob: 14.506104, label: tabby, tabby cat
class id: 282, prob: 13.106445, label: tiger cat
class id: 285, prob: 12.215820, label: Egyptian cat
class id: 287, prob: 8.143799, label: lynx, catamount
class id: 478, prob: 7.889282, label: carton
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 | mobilenetv2 | 224×224 | 6.5 ms | 1.9 ms | 3.1 ms | 11.5 ms | 322.6 FPS |