东方耀AI技术分享

标题: 海思AI芯片开发之运行NNIE demo程序 [打印本页]

作者: 东方耀    时间: 2020-7-24 09:46
标题: 海思AI芯片开发之运行NNIE demo程序
海思AI芯片开发之运行NNIE demo程序



海思芯片AI算法开发流程为:
1、离线模型训练:利用主流的深度学习框架,如caffe、TensorFlow、pyTorch、MXNet,训练神经网络模型。
由于海思NNIE工具链编译要求只能输入caffe格式的模型文件,因此其它深度学习框架训练的模型,需要转换为caffe格式的模型文件;
2、模型量化编译:将caffe格式的模型文件编译成海思AI芯片NNIE运行的格式文件*.wk,
同时利用校准图片集(多张量化)进行模型量化校准;
3、仿真调试:在PC机上,通过软件仿真调试器,加载编译生成的wk模型文件,对测试图片进行推理测试,验证算法模型的准确性,评估模型精度;
4、板上运行:经PC仿真验证评估后,在AI芯片上,初始化阶段,由CPU负责加载wk模型到NNIE硬件引擎上。
预测推理阶段,由CPU负责准备图像数据,调用NNIE引擎进行推理,最后获取推理结果。


正常情况下,步骤3和4在相同测试图片下,得出的结果一致,步骤3方便算法开发人员验证评估,步骤4才是最终的运行方式。



在芯片上运行示例程序:
安装海思sdk包:http://www.ai111.vip/thread-1061-1-1.html

cd dfy_softwares2/Hi3516CV500_SDK_V2.0.1.1/

找到海思开发包的参考程序,目录路径为:
smp/a7_linux/mpp/sample/


进入参考程序的nnie目录,执行make编译
smp/a7_linux/mpp/sample/svp/nnie   make

将编译结果sample_nnie_main和data目录所有文件上传到摄像头模组/mnt/mtd目录下(df -hT查看分区使用情况)



/mnt/mtd # ./sample_nnie_main
Usage : ./sample_nnie_main <index>
index:
         0) RFCN(VI->VPSS->NNIE->VGS->VO).
         1) Segnet(Read File).
         2) FasterRcnnAlexnet(Read File).
         3) FasterRcnnDoubleRoiPooling(Read File).
         4) Cnn(Read File).
         5) SSD(Read File).
         6) Yolov1(Read File).
         7) Yolov2(Read File).
         8) Yolov3(Read File).
         9) LSTM(Read File).
         a) Pvanet(Read File).
         b) Rfcn(Read File).
/mnt/mtd #
/mnt/mtd # ./sample_nnie_main 4
[Level]ebug,[Func]:SAMPLE_COMM_SVP_CheckSysInit [Line]:81 [Info]:Svp mpi init ok!
[Level]:Info,[Func]:SAMPLE_SVP_NNIE_Cnn [Line]:909 [Info]:Cnn Load model!
[Level]:Info,[Func]:SAMPLE_SVP_NNIE_Cnn [Line]:918 [Info]:Cnn parameter initialization!
[Level]:Info,[Func]:SAMPLE_SVP_NNIE_Cnn [Line]:930 [Info]:Cnn start!
[Level]:Info,[Func]:SAMPLE_SVP_NNIE_Cnn [Line]:951 [Info]:Cnn result:
[Level]:Info,[Func]:SAMPLE_SVP_NNIE_Cnn_PrintResult [Line]:875 [Info]:==== The 0th image info====
[Level]:Info,[Func]:SAMPLE_SVP_NNIE_Cnn_PrintResult [Line]:879 [Info]:0:4096
[Level]:Info,[Func]:SAMPLE_SVP_NNIE_Cnn_PrintResult [Line]:879 [Info]:1:0
[Level]:Info,[Func]:SAMPLE_SVP_NNIE_Cnn_PrintResult [Line]:879 [Info]:2:0
[Level]:Info,[Func]:SAMPLE_SVP_NNIE_Cnn_PrintResult [Line]:879 [Info]:3:0
[Level]:Info,[Func]:SAMPLE_SVP_NNIE_Cnn_PrintResult [Line]:879 [Info]:4:0
[Level]ebug,[Func]:SAMPLE_COMM_SVP_CheckSysExit [Line]:94 [Info]:Svp mpi exit ok!
/mnt/mtd # ./sample_nnie_main 8
[Level]ebug,[Func]:SAMPLE_COMM_SVP_CheckSysInit [Line]:81 [Info]:Svp mpi init ok!
[Level]:Info,[Func]:SAMPLE_SVP_NNIE_Yolov3 [Line]:3393 [Info]:Yolov3 Load model!
[Level]:Info,[Func]:SAMPLE_SVP_NNIE_Yolov3 [Line]:3402 [Info]:Yolov3 parameter initialization!
[Level]:Info,[Func]:SAMPLE_SVP_NNIE_Yolov3 [Line]:3409 [Info]:Yolov3 start!
[Level]:Info,[Func]:SAMPLE_SVP_NNIE_Yolov3 [Line]:3446 [Info]:Yolov3 result:
[Level]:Info,[Func]:SAMPLE_SVP_NNIE_Detection_PrintResult [Line]:1078 [Info]:==== The 2th class box info====
[Level]:Info,[Func]:SAMPLE_SVP_NNIE_Detection_PrintResult [Line]:1091 [Info]:59 92 312 311 0.996338
[Level]:Info,[Func]:SAMPLE_SVP_NNIE_Detection_PrintResult [Line]:1078 [Info]:==== The 8th class box info====
[Level]:Info,[Func]:SAMPLE_SVP_NNIE_Detection_PrintResult [Line]:1091 [Info]:257 60 374 121 0.957520
[Level]:Info,[Func]:SAMPLE_SVP_NNIE_Detection_PrintResult [Line]:1078 [Info]:==== The 17th class box info====
[Level]:Info,[Func]:SAMPLE_SVP_NNIE_Detection_PrintResult [Line]:1091 [Info]:65 165 175 387 0.999268
[Level]ebug,[Func]:SAMPLE_COMM_SVP_CheckSysExit [Line]:94 [Info]:Svp mpi exit ok!
/mnt/mtd #





cnn例子中,读取手写体0的图片数据文件./data/nnie_image/y/0_28x28.y,程序正确的预测出数字0。

yolov3例子中,对图片数据文件./data/nnie_image/rgb_planar/dog_bike_car_416x416.bgr进行目标检测。















欢迎光临 东方耀AI技术分享 (http://www.ai111.vip/) Powered by Discuz! X3.4