继上文开箱后,本文主要依托爱芯元智官方的实例,进行官方YOLOV5模型的部署和测试。
一、环境搭建
由于8核A55的SoC,加上目前Debian OS的工具齐全,所以决定直接在板上编译程序。
root@maixbox:~# lscpu
Architecture: aarch64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 8
On-line CPU(s) list: 0-7
Vendor ID: ARM
Model name: Cortex-A55
Model: 0
Thread(s) per core: 1
Core(s) per cluster: 8
Socket(s): -
Cluster(s): 1
Stepping: r2p0
CPU(s) scaling MHz: 100%
CPU max MHz: 1700.0000
CPU min MHz: 1200.0000
BogoMIPS: 48.00
Flags: fp asimd evtstrm crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp
开发工具什么的全部装上,apt install build-essential libopencv-dev cmake
。看看gcc版本。
root@maixbox:~# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/aarch64-linux-gnu/12/lto-wrapper
Target: aarch64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 12.2.0-14' --with-bugurl=file:///usr/share/doc/gcc-12/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-12 --program-prefix=aarch64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libquadmath --disable-libquadmath-support --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --enable-fix-cortex-a53-843419 --disable-werror --enable-checking=release --build=aarch64-linux-gnu --host=aarch64-linux-gnu --target=aarch64-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.0 (Debian 12.2.0-14)
二、源码下载&编译
首先,git clone https://github.com/AXERA-TECH/ax-samples.git
下载源码到本地。
然后,指定芯片为AX650,cmake生成makefile。
cd ax-samples
mkdir build && cd build
cmake -DBSP_MSP_DIR=/soc/ -DAXERA_TARGET_CHIP=ax650 ..
第三步,make -j8
,既然8核,那就-j8全速。
过一会等编译完成。
最后,make install
。可以看到生成的可执行示例存放在build/install/ax650/ 路径下。
其中很多案例程序,因为智能教室需要清点人数,所以选择了YOLOV5和YOLOV7_TINY face两个demo。
三、下载模型
爱芯元智官方自己搞了个ModelZoo,类似于AMD Vitis AI 的Vitis AI Model Zoo工具,主要是提供AXERA芯片平台的通用AI模型(具体baidu盘链接为 https://pan.baidu.com/s/1CCu-oKw8jUEg2s3PEhTa4g?pwd=xq9f ),直接下载下来使用。
因为本文需要部署人脸识别模型,所以下载了yolov7-tiny-face.axmodel和yolov5s-face.axmodel两个模型文件。
四、测试
选择了一张不错的关于教室课堂的测试图片。
(一)YOLOV5人脸识别
root@maixbox:~/ax-samples/build/install/ax650# ./ax_yolov5_face -m /root/yolov5s-face.axmodel -i /root/CLASS.jpg
model file : /root/yolov5s-face.axmodel
image file : /root/CLASS.jpg
img_h, img_w : 640 640
Engine creating handle is done.
Engine creating context is done.
Engine get io info is done.
Engine alloc io is done.
Engine push input is done.
post process cost time:0.39 ms
Repeat 1 times, avg time 7.80 ms, max_time 7.80 ms, min_time 7.80 ms
detection num: 5
0: 87%, [ 145, 113, 226, 218], face
0: 87%, [ 338, 160, 419, 254], face
0: 81%, [ 519, 138, 561, 184], face
0: 81%, [ 604, 250, 647, 294], face
0: 77%, [ 495, 265, 536, 311], face
五张人脸识别耗时7.8ms,识别准确率较高,识别后的图片如下:
(二)YOLOV7_TINY人脸识别
root@maixbox:~/ax-samples/build/install/ax650# ./ax_yolov7_tiny_face -m /root/yolov7-tiny-face.axmodel -i /root/CLASS.jpg
model file : /root/yolov7-tiny-face.axmodel
image file : /root/CLASS.jpg
img_h, img_w : 640 640
Engine creating handle is done.
Engine creating context is done.
Engine get io info is done.
Engine alloc io is done.
Engine push input is done.
post process cost time:0.84 ms
Repeat 1 times, avg time 8.98 ms, max_time 8.98 ms, min_time 8.98 ms
detection num: 5
0: 88%, [ 147, 115, 224, 218], face
0: 88%, [ 344, 159, 415, 252], face
0: 84%, [ 520, 137, 560, 185], face
0: 84%, [ 605, 250, 644, 296], face
0: 74%, [ 498, 267, 535, 311], face
五张人脸识别耗时8.98ms,识别准确率总体比YOLOV5高,识别后的图片如下:
五、总结
得益于官方案例,开发者可以很方便的在爱芯元智SoC硬件平台上部署常见的深度学习算法模型,方便开发者快速评估和适配业务。