首页 > 编程知识 正文

ncnn param解析参数含义,ncnn param文件参数的含义

时间:2023-05-05 09:07:18 阅读:218616 作者:3692

LeNet模型为例

由Caffe的lenet_deploy.prototxt文件转换得到

name: "LeNet"layer { name: "data" type: "Input" top: "data" input_param { shape: { dim: 1 dim: 1 dim: 28 dim: 28 } }}layer { name: "conv1" type: "Convolution" bottom: "data" top: "conv1" param { lr_mult: 1 } param { lr_mult: 2 } convolution_param { num_output: 20 kernel_size: 5 stride: 1 weight_filler { type: "xavier" } bias_filler { type: "constant" } }}layer { name: "pool1" type: "Pooling" bottom: "conv1" top: "pool1" pooling_param { pool: MAX kernel_size: 2 stride: 2 }}layer { name: "conv2" type: "Convolution" bottom: "pool1" top: "conv2" param { lr_mult: 1 } param { lr_mult: 2 } convolution_param { num_output: 50 kernel_size: 5 stride: 1 weight_filler { type: "xavier" } bias_filler { type: "constant" } }}layer { name: "pool2" type: "Pooling" bottom: "conv2" top: "pool2" pooling_param { pool: MAX kernel_size: 2 stride: 2 }}layer { name: "ip1" type: "InnerProduct" bottom: "pool2" top: "ip1" param { lr_mult: 1 } param { lr_mult: 2 } inner_product_param { num_output: 500 weight_filler { type: "xavier" } bias_filler { type: "constant" } }}layer { name: "relu1" type: "ReLU" bottom: "ip1" top: "ip1"}layer { name: "ip2" type: "InnerProduct" bottom: "ip1" top: "ip2" param { lr_mult: 1 } param { lr_mult: 2 } inner_product_param { num_output: 10 weight_filler { type: "xavier" } bias_filler { type: "constant" } }}layer { name: "prob" type: "Softmax" bottom: "ip2" top: "prob"} param文件: 77675179 9Input data 0 1 data 0=28 1=28 2=1Convolution conv1 1 1 data conv1 0=20 1=5 2=1 3=1 4=0 5=1 6=500Pooling pool1 1 1 conv1 pool1 0=0 1=2 2=2 3=0 4=0Convolution conv2 1 1 pool1 conv2 0=50 1=5 2=1 3=1 4=0 5=1 6=25000Pooling pool2 1 1 conv2 pool2 0=0 1=2 2=2 3=0 4=0InnerProduct ip1 1 1 pool2 ip1 0=500 1=1 2=400000ReLU relu1 1 1 ip1 ip1_relu1InnerProduct ip2 1 1 ip1_relu1 ip2 0=10 1=1 2=5000Softmax prob 1 1 ip2 prob 0=0

第一行:版本信息
数值为此param文件的版本
ncnn相关源码说明:

int magic = 0; fscanf(fp, "%d", &magic); if (magic != 7767517) { fprintf(stderr, "param is too old, please regeneraten"); return -1; }

第二行:层与数据交换结构数量
第一个数字:层(layer)的数量
第二个数字:数据交换结构(blob)的数量
ncnn相关源码说明:

// parse int layer_count = 0; int blob_count = 0; fscanf(fp, "%d %d", &layer_count, &blob_count);

第三行及以下:相关层的具体信息
input层比较特殊一点
前4个值的含义固定:
(1)层类型
(2)层名称
(3)输入数据结构数量(bottom blob)
(4)输出数据结构数量(top blob)
后面跟有三个不同类型的值,严格按照顺序排序

(1) 网络输入层名(一个层可能有多个输入,则有多个网络输入层名)
(2) 网络输出层名(一个层可能有多个输出,则有多个网络输出层名)
(3)特殊参数(可能没有): 一种是k=v的类型;另一种是k=len,v1,v2,v3….(数组类型)。该层在ncnn中是存放到paramDict结构中,不同类型层,各种参数意义不一样。

以第一个卷积层为例

层类型:Convolution
层名称:conv1
输入数据结构数量:1
输出数据结构数量(top blob):1
网络输入层名:data
网络输出层名:conv1
特殊参数1:0=20,num_output: 20
特殊参数2:1=5,kernel_size: 5
特殊参数3:2=1,stride: 1
特殊参数4:3=1
特殊参数5:4=0
特殊参数6:5=1
特殊参数7:6=500,该层的参数量,5*5*1*20=500

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。