【触觉智能Purple Pi开发板试用】FastestDet目标检测模型应用
0x0 介绍 FastestDet
https://github.com/dog-qiuqiu/FastestDet
FastestDet: 比yolo-fastest更快!更强!更简单!全新设计的超实时Anchor-free目标检测算法
模型大小 250K,非常适合嵌入式平台应用
0x1 配置ncnn库路径
下载FastestDet仓库,example/ncnn 目录中有写好的ncnn程序和模型文件
git clone https://github.com/dog-qiuqiu/FastestDet
接上篇,交叉编译好ncnn,再执行make install
,会在 build/install 安装ncnn库的 lib 和 include
把lib和include文件夹复制到 FastestDet/example/ncnn 目录里
修改 FastestDet/example/ncnn/build.sh,去除opencv依赖
export TOOLCHAIN_ROOT_PATH=/home/nihui/osd/PurPle-Pi-R1/toolchain/gcc-arm-8.2-2018.08-x86_64-arm-linux-gnueabihf
$TOOLCHAIN_ROOT_PATH/bin/arm-linux-gnueabihf-g++ -O3 -o FastestDet FastestDet.cpp -I include/ncnn lib/libncnn.a -fopenmp
打开 FastestDet.cpp
#include <opencv2/opencv.hpp>
改为
#include "simpleocv.h"
即使用 ncnn simpleocv 替代opencv
最后执行 build.sh,编译出 FastestDet 程序
0x2 测试 FastestDet
将编译好的 FastestDet 连同 FastestDet模型文件,一起上传到开发板
scp FastestDet FastestDet.param FastestDet.bin root@192.168.31.188:/root/
再上传待检测的输入图
scp 3.jpg root@192.168.31.188:/root/
执行 FastestDet 程序进行目标检测,在终端显示检测的物体区域和类别
# ./FastestDet
ncnn model load sucess...
output: 85, 22, 22
Time: 325.84 ms
x1:40 y1:62 x2:178 y2:294 person:90.04%
x1:288 y1:141 x2:482 y2:296 person:89.44%
x1:159 y1:136 x2:256 y2:265 person:80.59%
x1:231 y1:138 x2:322 y2:277 person:77.92%
FastestDet 会把检测结果画在图片,保存在 result.jpg,下载图片即可在本地看到结果图
scp root@192.168.31.188:/root/result.jpg ./
对比FastestDet官方给出的结果图,精度一丝不差,字体也好看了一些 23333
![result0.jpg](//file.elecfans.com/web2/M00/7E/14/poYBAGODbqGAWbZGAAFqHar510k764.jpg)
![result1.jpg](//file.elecfans.com/web2/M00/7E/A1/pYYBAGODbyeAXUZ3AAIP38RrQs8117.jpg)
我们再利用下bf16加速看看,修改 FastestDet.cpp,在加载模型前设置开启bf16开关
ncnn::Net net;
net.opt.use_bf16_storage = true;
net.load_param("FastestDet.param");
net.load_model("FastestDet.bin");
重新build.sh编译,上传,执行,可以看到检测耗时有明显缩短
# ./FastestDet
ncnn model load sucess...
output: 85, 22, 22
Time: 260.82 ms
x1:288 y1:142 x2:482 y2:296 person:88.40%
x1:40 y1:63 x2:179 y2:292 person:88.15%
x1:158 y1:135 x2:257 y2:265 person:79.14%
x1:228 y1:139 x2:324 y2:277 person:76.71%
对比bf16的结果,在框的位置上有细微差别,依然可以接受 :D
![result.jpg](//file.elecfans.com/web2/M00/7E/14/poYBAGODbpOALZrIAAINzUHNPEQ755.jpg)
![result1.jpg](//file.elecfans.com/web2/M00/7E/A1/pYYBAGODbyeAXUZ3AAIP38RrQs8117.jpg)