.prototxt文件 定义了网络的结构,我们可以通过它了解网络是如何设计的,也可以建立属于自己的网络。这种格式来源于Google的Protocol Buffers,后来被开源,主要用于海量数据存储、传输协议格式等场合。https://blog.csdn.net/liuyuzhu111/article/details/52253491
针对xml解析对时间和空间的开销较大的缺点进行了改进,兼容多种语言,向前/向后兼容,具有生成代码的机制。
lenet_train_test.prototxt 是经典的lenet网络的文件,使用在MNIST手写字符分类中。下面是对它的一些简单的注释
name: "LeNet"
layer {
name: "mnist"
type: "Data"
top: "data" //输出data
top: "label" //输出标签
include {
phase: TRAIN //在训练阶段才在网络中加入这一层
}
transform_param {
#mean_file: "mean.binaryproto" //均值文件
scale: 0.00390625 //对所有的图片归一化到0~1之间,也就是对输入数据全部乘以scale,0.0039= 1/255
}
data_param {
source: "examples/mnist/mnist_train_lmdb" // 从指定路径读取文件 所以没有bottom
batch_size: 64 //batch大小是64 太大不行 太小也不行 等于1时是online learning
backend: LMDB //数据类型是lmdb
}
}
layer {
name: "mnist"
type: "Data"
top: "data"
top: "label"
include {
phase: TEST //在测试阶段才在网络中加入这一层
}
transform_param {
#mean_file: "mean.binaryproto"
scale: 0.00390625
}
data_param {
source: "examples/mnist/mnist_test_lmdb"
batch_size: 100
backend: LMDB
}
}
layer {
name: "conv1"
type: "Convolution"
bottom: "data"
top: "conv1"
param {
lr_mult: 1 //学习率 在这种情况下,我们将设置权重学习率与求解器在运行时给出的学习率相同,
//并且偏差学习率为此的两倍 - 这通常会导致更好的收敛率。
}
param {
lr_mult: 2
}
convolution_param {
num_output: 20 //产生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 //每个pool大小是2x2
stride: 2 //步长2,大小2x2,所以没有重叠
}
}
layer {
name: "conv2"
type: "Convolution"
bottom: "pool1" //连接在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 { //同址计算(in-place computation,返回值覆盖原值而占用新的内存)
//neuron_layers.hpp中,其派生类主要是元素级别的运算(比如Dropout运算,激活函数ReLu,Sigmoid等
name: "relu1"//ReLU是按元素操作的,in-place操作,节省内存
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: "accuracy"
type: "Accuracy"
bottom: "ip2"
bottom: "label"
top: "accuracy"
include { //决定了这一层什么时候被包含在网络中
phase: TEST // accuracy只存在于测试阶段
}
}
layer {
name: "loss"
type: "SoftmaxWithLoss"
bottom: "ip2"
bottom: "label"
top: "loss"
}