train_val.prototxt:
name: "CaffeNet" # 网络名
layer { # 数据层
name: "data"
type: "Data"
top: "data"
top: "label"
include {
phase: TRAIN # 表明这是在训练阶段才包括进去
}
transform_param { # 对数据进行预处理
mirror: true # 是否做镜像,默认为false
crop_size: 227 # 输入图像大小
mean_file: "data/ilsvrc12/imagenet_mean.binaryproto" # 减去均值文件,去图像冗余,value — value_mean
# scale,特征归一化系数,将范围为[0, 255]的 MNIST 数据归一化为[0, 1],默认为1
}
# mean pixel / channel-wise mean instead of mean image
# transform_param {
# crop_size: 227
# mean_value: 104
# mean_value: 117
# mean_value: 123
# mirror: true
# }
data_param { # 设定数据来源
source: "examples/imagenet/ilsvrc12_train_lmdb" # 数据库文件的路径
batch_size: 256 # 网络单次输入数据的数量
backend: LMDB # 需要转换成的db文件格式,可选为LEVELDB或LMDB, 默认为LEVELDB
}
}
layer {
name: "data"
type: "Data"
top: "data"
top: "label"
include {
phase: TEST # 表明这是在测试阶段才包括进去
}
transform_param {
mirror: false # 是否做镜像,256×256随机选取224×224,然后再加上水平翻转的噪声,使得数据集扩大了2048倍,防止过拟合
crop_size: 227
mean_file: "data/ilsvrc12/imagenet_mean.binaryproto" # 减去均值文件
}
# mean pixel / channel-wise mean instead of mean image
# transform_param {
# crop_size: 227
# mean_value: 104
# mean_value: 117
# mean_value: 123
# mirror: false
# }
data_param {
source: "examples/imagenet/ilsvrc12_val_lmdb" # 数据库文件的路径
batch_size: 50 # 网络单次输入数据的数量
backend: LMDB # 选择使用 LEVELDB 还是 LMDB
}
}
layer {
name: "conv1" # 卷积层1
type: "Convolution" # Convolution层使用一系列可训练的卷积核对输入图像进行卷积操作,每组卷积核生成输出图像中的一个特征图。
bottom: "data"
top: "conv1"
param {
lr_mult: 1 # 学习率,但是最终的学习率需要乘以solver.prototxt 配置文件中的base_lr
decay_mult: 1 # 权值衰减,为了避免模型的over-fitting,需要对cost function加入规范项
}
param {
lr_mult: 2 # 如果有两个lr_mult, 则第一个表示weight的学习率,第二个表示bias的学习率,一般bias的学习率是weight学习率的2倍
decay_mult: 0
}
convolution_param {
num_output: 96 # 卷积核(filter)的个数为96
kernel_size: 11 # 卷积核的大小,如果卷积核的长和宽不等,需要用 kernel_h 和 kernel_w 分别设定
stride: 4 # 卷积核的步长,默认为1,也可以用stride_h和stride_w来设置
weight_filler { # 权值初始化,默认为“constant”,值全为0
type: "gaussian" # 使用高斯分布随机初始化卷积核,很多时候我们用”xavier”算法来进行初始化
# 初始化的方式有很多种,分别为常量初始化(constant)、高斯分布初始化(gaussian)、positive_unitball初始化、
# 均匀分布初始化(uniform)、xavier初始化、msra初始化、双线性初始化(bilinear)
std: 0.01 # 高斯分布的标准差为0.01(默认均值:0)
}
bias_filler {
type: "constant" # 使用常数0初始化偏置项
value: 0
}
}
}
layer {
name: "relu1" # ReLU非线性激活层1
type: "ReLU"
bottom: "conv1"
top: "conv1"
}
layer {
name: "pool1" # 池化层1
type: "Pooling"
bottom: "conv1"
top: "pool1"
pooling_param {
pool: MAX # 池化方法,默认为MAX。目前可用的方法有 MAX,AVE,或STOCHASTIC
kernel_size: 3 # 池化大小:3×3
stride: 2 # 池化步长:2
}
}
layer {
name: "norm1" # 规范化层1
type: "LRN" # 局部响应值归一化,通过对输入数据的局部归一操作执行了一种“侧抑制”的机制。
bottom: "pool1"
top: "norm1"
lrn_param {
local_size: 5 # 对于跨通道的归一化,该参数指参与求和的通道数,对于通道内的规范化,该参数指的是参与求和的方形区域的边长
alpha: 0.0001 # 尺度参数 在以当前输入值为中心的区域内计算加和
beta: 0.75 # 指数参数 每个输入值除以(1+(alpha/n)∑(x^2))^bata以实现归一化,其中n是局部区域的大小
}
}
layer {
name: "conv2" # 卷积层2
type: "Convolution"
bottom: "norm1"
top: "conv2"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 256 # 卷积核(filter)的个数为256
pad: 2 # 指定在输入图像周围补0的像素个数,默认为0,不扩充,扩充的时候是左右、上下对称的,或者pad_h和pad_w
# 比如卷积核的大小为5*5,那么pad设置为2,则四个边缘都扩充2个像素,即宽度和高度都扩充了4个像素
# 这样卷积之后特征图就不会变小
kernel_size: 5
group: 2 # 分组,默认为1组。如果大于1,我们限制卷积的连接操作在一个子集内,卷积分组可以减少网络的参数
# 每个input是需要和每一个kernel都进行连接的,但是由于分组的原因其只是与部分的kernel进行连接的
# 如: 我们根据图像的通道来分组,那么第i个输出分组只能与第i个输入分组进行连接。
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
value: 1
}
}
}
layer {
name: "relu2" # ReLU非线性激活层2
type: "ReLU"
bottom: "conv2"
top: "conv2"
}
layer {
name: "pool2" # 池化层2
type: "Pooling"
bottom: "conv2"
top: "pool2"
pooling_param {
pool: MAX
kernel_size: 3
stride: 2
}
}
layer {
name: "norm2" # 规范化层2
type: "LRN"
bottom: "pool2"
top: "norm2"
lrn_param {
local_size: 5
alpha: 0.0001
beta: 0.75
}
}
layer {
name: "conv3" # 卷积层3
type: "Convolution"
bottom: "norm2"
top: "conv3"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 384 # 卷积核(filter)的个数为384
pad: 1
kernel_size: 3
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
value: 0
}
}
}
layer {
name: "relu3" # ReLU非线性激活层3
type: "ReLU"
bottom: "conv3"
top: "conv3"
}
layer {
name: "conv4"
type: "Convolution"
bottom: "conv3"
top: "conv4"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 384
pad: 1
kernel_size: 3
group: 2
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
value: 1
}
}
}
layer {
name: "relu4"
type: "ReLU"
bottom: "conv4"
top: "conv4"
}
layer {
name: "conv5"
type: "Convolution"
bottom: "conv4"
top: "conv5"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 256
pad: 1
kernel_size: 3
group: 2
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
value: 1
}
}
}
layer {
name: "relu5"
type: "ReLU"
bottom: "conv5"
top: "conv5"
}
layer {
name: "pool5"
type: "Pooling"
bottom: "conv5"
top: "pool5"
pooling_param {
pool: MAX
kernel_size: 3
stride: 2
}
}
layer {
name: "fc6"
type: "InnerProduct"
bottom: "pool5"
top: "fc6"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
inner_product_param {
num_output: 4096
weight_filler {
type: "gaussian"
std: 0.005
}
bias_filler {
type: "constant"
value: 1
}
}
}
layer {
name: "relu6"
type: "ReLU"
bottom: "fc6"
top: "fc6"
}
layer {
name: "drop6" # Dropout层
type: "Dropout"
bottom: "fc6"
top: "fc6"
dropout_param {
dropout_ratio: 0.5 # 丢弃数据(节点和连接)的概率
}
}
layer {
name: "fc7"
type: "InnerProduct"
bottom: "fc6"
top: "fc7"
param {
lr_mult: 1 # 局部学习率
decay_mult: 1 # 权值衰减因子
}
param {
lr_mult: 2 # bias的学习率,一般为上面w的两倍
decay_mult: 0 # bias的权值衰减因子
}
inner_product_param {
num_output: 4096 #相当于1×1×4096,全连接层的4096相当于卷积核的个数,全连接的每个节点,实际就是卷积核大小为图片大小的卷积运算。(不加pad)
weight_filler {
type: "gaussian"
std: 0.005
}
bias_filler {
type: "constant"
value: 1
}
}
}
layer {
name: "relu7"
type: "ReLU"
bottom: "fc7"
top: "fc7"
}
layer {
name: "drop7"
type: "Dropout"
bottom: "fc7"
top: "fc7"
dropout_param {
dropout_ratio: 0.5 #默认为0.5
}
}
layer {
name: "fc8"
type: "InnerProduct"
bottom: "fc7"
top: "fc8"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
inner_product_param {
num_output: 1000 #相当于1×1×1000
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
value: 0
}
}
}
layer {
name: "accuracy"
type: "Accuracy"
bottom: "fc8"
bottom: "label"
top: "accuracy"
include {
phase: TEST # 表明这是在测试阶段才包括进去
}
}
layer {
name: "loss"
type: "SoftmaxWithLoss"
bottom: "fc8"
bottom: "label"
top: "loss"
# 默认loss_weight: 1
}
# 没有出现的属性: 可查看caffe文档看看可选还是必选,再根据自己的需要选择
# bias_term 是否开启偏置项,默认为true, 开启
# train_val.prototxt 网络流程定义顺序一般为
# 数据层(分别包含训练阶段/测试阶段的定义) -> 卷积层(Conv) -> 非线性激活层(ReLU) -> 池化层(Pooling) -> 规范化层(Norm(LRN)) -> ...
... -> 卷积层(Conv) -> 非线性激活层(ReLU) -> 池化层(Pooling)-> 全连接层(FC(InnerProduct)) -> 非线性激活层(ReLU) -> Dropout层 -> 全连接层(FC(InnerProduct)) -> Accuracy层(测试阶段) -> SoftmaxWithLoss层
caffe学习笔记9-train_val.prototxt学习
最新推荐文章于 2020-03-14 23:56:28 发布