MNN模型编译和转换过程

MNN模型编译和转换过程

~模型转换过程

1:首先编译MNN的模型转换工具: ./MNNConvert    
cd MNN/
 MNN/
./schema/generate.sh
/schema/generate.sh
mkdir build
kdir build
cd build
 build
cmake .. -DMNN_BUILD_CONVERTER=true && make -j8
make .. -DMNN_BUILD_CONVERTER=true && make -j8

 

    2:调用 . /MNNConvert 转换给TF,CAFFE,ONNX,TFLITE,转换为MNN模型    
#官方示例一  
./MNNConvert -f TF --modelFile ../model/model-mobilenet_v1_075.pb --MNNModel model3.mnn --bizCode biz

#官方示例三
./MNNConvert -f TFLITE --modelFile ../model/mobilenet_v2_1.0_224.tflite --MNNModel mobilent_dax.mnn --bizCode biz
    编译后的文件和模型存在于build中,所以转换和测试需要在此文件下使用工具   得到model3.mnn模型

~模型测试 

测试代码如下:        
#示例一
 ./multiPose.out model3.mnn 2.jpg pose.png

#以下是输出内容  每次运行时间有稍微变化
main, 381, cost time: 1.360000 ms
ain, 381, cost time: 1.360000 ms
main, 405, cost time: 0.060000 ms
ain, 405, cost time: 0.060000 ms


#示例二
 ./segment.out MNN_deeplab.mnn 3.jpg result.png

#结果如下
input: w:257 , h:257, bpp: 3
origin size: 678, 452
Mask: w=257, h=257, c=21


#示例三
 ./pictureRecognition.out mobilent_dax.mnn dax.png ../demo/model/MobileNet/synset_words.txt
#结果
Can't Find type=4 backend, use 0 instead
Can't Find type=4 backend, use 0 instead
input: w:224 , h:224, bpp: 3
origin size: 746, 497
output size:1001
echidna, spiny anteater, anteater: 0.273970
lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens: 0.206582
African elephant, Loxodonta africana: 0.082232
water buffalo, water ox, Asiatic buffalo, Bubalus bubalis: 0.006365
Ibizan hound, Ibizan Podenco: 0.005900
bison: 0.005519
sea slug, nudibranch: 0.003803
isopod: 0.003659
Border terrier: 0.003178
totem pole: 0.002906
  
  直接在build执行命令会报错如下,一般都是模型转换出错,重新转换模型即可。          
Create interpreter failed, open moiblenet.mnn error
Can't Find type=4 backend, use 0 instead
或者
Can't Find type=4 backend, use 0 instead
Can't Find type=4 backend, use 0 instead
Compute Shape Error for MobilenetV2/Conv/BatchNorm/FusedBatchNorm
段错误(吐核)
 
   

 

   
上一篇:LeetCode30 HashMap 滑动窗口解决 getOrDefault()方法


下一篇:MNN初学安装编译windows版