caffe 各层的解释
参考:
http://www.cnblogs.com/denny402/tag/caffe/default.html?page=1
http://blog.csdn.net/u011762313/article/category/5705779/1
对caffe各层的理解:
层有很多类型,比如Data,Convolution,Pooling等,层之间的数据是以Blobs的方式进行。
下面介绍对各层的解释:
一.数据层
数据层是每个模型的最底层,通常的数据预处理在这一层实现,例如:
layer {
name: "mnist"
type: "Data"
top: "data"
top: "label"
include {
phase: TRAIN
}
transform_param {
scale: 0.00390625
}
data_param {
source: "examples/mnist/mnist_train_lmdb"
batch_size: 64
backend: LMDB
}
}
类型Data表示数据来源为LEVELDB或LMDB;
bottom表示输入数据,top表示输出数据;在数据层一般输出配对的(data,label);
include中的参数用来指示是训练还是测试;
transform_param表示将数据变换到特定范围内,0.00390625也就是1/255,表示将数据归一化到0-1之间;
data_param中设置数据的来源,batch_size的大小,数据格式等。
二.视觉层
视觉层包括Convolution层,Pooling层等
卷积层:
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"
}
}
}
lr_mult表示学习学习速率,最终的学习速率等于这个数乘以solver.prototxt中的base_lr。如果有两个lr_mult,一个表示权值的学习速率,一个表示偏置的学习速率。
convolution_param为卷积层的参数,num_output表示卷积核的个数;kernel_size表示卷积核的大小;stride表示步长;weight_filler表示权值初始化,xavier表示用该算法初始化权值;bias_filler表示偏置初始化,constant表示初始化值为0.
池化层:
layer {
name: "pool1"
type: "Pooling"
bottom: "conv1"
top: "pool1"
pooling_param {
pool: MAX
kernel_size: 2
stride: 2
}
}
pooling_param表示池化层参数,pool表示池化的方法,这里是最大池化;kernel_size表示卷积核大小;stride表示步长。
三.激活层
layer {
name: "relu1"
type: "ReLU"
bottom: "ip1"
top: "ip1"
}
标准的ReLU函数为max(x,0),当x>0时,输出x,当x<0时,
四.其他层
全连接层:InnerProduct表示全连接层
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"
}
}
}
lr_mult表示学习学习速率,最终的学习速率等于这个数乘以solver.prototxt中的base_lr。如果有两个lr_mult,一个表示权值的学习速率,一个表示偏置的学习速率。
全连接层参数inner_product_param与卷积层参数设置类似。
Accuracy层:输出分类精确度,只有test阶段才有。
layer {
name: "accuracy"
type: "Accuracy"
bottom: "ip2"
bottom: "label"
top: "accuracy"
include {
phase: TEST
}
}
Softmax-loss层:输出loss值
layer {
name: "loss"
type: "SoftmaxWithLoss"
bottom: "ip2"
bottom: "label"
top: "loss"
}
对caffe中的solver的理解:
# The train/test net protocol buffer definition 第一行指出模型文件的位置,文件路径从caffe根目录开始。
net: "examples/mnist/lenet_train_test.prototxt"
# test_iter specifies how many forward passes the test should carry out.
# In the case of MNIST, we have test batch size 100 and 100 test iterations,
# covering the full 10,000 testing images.
test_iter: 100
# Carry out testing every 500 training iterations.测试间隔,每训练500次才进行一次测试
test_interval: 500
# The base learning rate, momentum and the weight decay of the network.
base_lr: 0.01#基础学习速率
momentum: 0.9#上一次梯度更新的权重#默认优化类型为SGD,即梯度下降法
weight_decay: 0.0005#权值衰减项,防止过拟合
# The learning rate policy####下面三个参数代表参数调整策略
lr_policy: "inv"
gamma: 0.0001
power: 0.75
# Display every 100 iterations
display: 100#每训练100次在屏幕上显示一次
# The maximum number of iterations
max_iter: 10000#最大迭代次数
# snapshot intermediate results#下面两个参数是指多久将训练出来的model和solver状态保存一次及保存的地址
snapshot: 5000
snapshot_prefix: "examples/mnist/lenet"
# solver mode: CPU or GPU
solver_mode: GPU#可选GPU和CPU
base_lr是基础学习速率,在学习过程中可对学习速率进行调整,调整的策略由lr_policy来设置,如果设置为inv,则返回的是base_lr*(1+gamma*iter)^(-power)
训练自己的数据
参考:
http://www.cnblogs.com/newbyang/p/5685358.html
http://blog.csdn.net/zr459927180/article/details/51001536
http://blog.csdn.net/u012878523/article/details/41698209
http://blog.csdn.net/u013657981/article/details/49497753