• -------------------------------------------------------------
  • ====================================

NCNN–网络结构文件.param解析

技能 dewbay 2年前 (2023-03-01) 1461次浏览 已收录 0个评论 扫描二维码

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 文件:

7767517
9 9
Input data 0 1 data 0=28 1=28 2=1
Convolution conv1 1 1 data conv1 0=20 1=5 2=1 3=1 4=0 5=1 6=500
Pooling pool1 1 1 conv1 pool1 0=0 1=2 2=2 3=0 4=0
Convolution conv2 1 1 pool1 conv2 0=50 1=5 2=1 3=1 4=0 5=1 6=25000
Pooling pool2 1 1 conv2 pool2 0=0 1=2 2=2 3=0 4=0
InnerProduct ip1 1 1 pool2 ip1 0=500 1=1 2=400000
ReLU relu1 1 1 ip1 ip1_relu1
InnerProduct ip2 1 1 ip1_relu1 ip2 0=10 1=1 2=5000
Softmax 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 regenerate\n”);
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


露水湾 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:NCNN–网络结构文件.param解析
喜欢 (0)
[]
分享 (0)
关于作者:
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址