ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

MNN配置

2019-11-19 16:51:01  阅读:425  来源: 互联网

标签:onnx 配置 benchmark names MNN input out


1、github链接:https://github.com/alibaba/MNN/tree/master/tools/converter

2、教程

(1)使用教程:https://www.bookstack.cn/read/MNN-zh/tools-converter-README_CN.md

(2)参考博客:https://blog.csdn.net/qq_37643960/article/details/97028743

(3)github的项目中的readme部分也有讲解;

安装过程:

编译安装MNN动态库和Convert转换工具,命令如下:

cd /MNN/
mkdir build
cd build
cmake .. -DMNN_BUILD_CONVERTER=true
make -j4

之后build文件夹中就会出现benchmark.out和MNNConvert可执行文件;

测试benchmark.out:

./benchmark.out ../benchmark/models/ 10 0

 

其中10表示前向传播10次,最后结果取平均值;0表示使用CPU;(执行推理的计算设备,有效值为 0(浮点 CPU)、1(Metal)、3(浮点OpenCL)、6(OpenGL),7(Vulkan))

测试MNNConvert:

./MNNConvert -h

 

测试:

第一步:将pytorch模型转换为onnx模型

import torch
import torchvision

dummy_input = torch.randn(10, 3, 224, 224, device='cuda')
model = torchvision.models.alexnet(pretrained=True).cuda()

# Providing input and output names sets the display names for values
# within the model's graph. Setting these does not change the semantics
# of the graph; it is only for readability.
#
# The inputs to the network consist of the flat list of inputs (i.e.
# the values you would pass to the forward() method) followed by the
# flat list of parameters. You can partially specify names, i.e. provide
# a list here shorter than the number of inputs to the model, and we will
# only set that subset of names, starting from the beginning.
input_names = [ "actual_input_1" ] + [ "learned_%d" % i for i in range(16) ]
output_names = [ "output1" ]

torch.onnx.export(model, dummy_input, "alexnet.onnx", verbose=True, input_names=input_names, output_names=output_names)

 

第二步:将onnx模型转换为mnn模型

./MNNConvert -f ONNX --modelFile alexnet.onnx --MNNModel alexnet.mnn --bizCode MNN

 

第三步:使用benchmark.out测试前向传播时间

./benchmark.out ./models/ 10 0

 PS:在/MNN/source/shape/ShapeSqueeze.cpp 80L中:注释掉那个NanAssert(),在新版函数中已经将它注释掉了;(要不然会报reshape的error)

标签:onnx,配置,benchmark,names,MNN,input,out
来源: https://www.cnblogs.com/zf-blog/p/11890537.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有