LeNet网络介绍
LeNet-5模型,大神Yann LeCun的作品,用以手写字体的识别,在邮编识别上得到应用,论文《Gradient-Based Learning Applied
to Document Recognition》堪称CNN开山之作。
LeNet网络详解
网络名称
name: "LeNet" # 网络(NET)名称为LeNet
mnist层-train
layer { # 定义一个层
name: "mnist" # 层名字mnist
type: "Data" # 层的类型,数据层
top: "data" # 层的输出blob有两个;data和label
top: "label" # blob是数据库中用来存储二进制文件的字段类型
include {
phase: TRAIN # 该层仅在训练阶段有效
}
transform_param {
scale: 0.00390625 # 数据变换使用的数据缩放因子
}
data_param { # 数据层参数
source: "A:/Caffe/caffe/examples/mnist/mnist-train-leveldb" # 数据路径
batch_size: 64 # 批量数目,一次读取64张图
backend: LEVELDB # 数据格式为LEVELDB
}
}
mnist层-test
layer { # 同是名为mnist且输出为data和label的数据层,只是定义的参数只在检测阶段有效
name: "mnist"
type: "Data"
top: "data"
top: "label"
include {
phase: TEST
}
transform_param {
scale: 0.00390625
}
data_param {
source: "A:/Caffe/caffe/examples/mnist/mnist-test-leveldb"
batch_size: 1
backend: LEVELDB
}
}
卷积层1
# lr_mult: 学习率的系数,最终的学习率是这个数乘以solver.prototxt配置文件中的base_lr。
# 如果有两个lr_mult, 则第一个表示权值的学习率,第二个表示偏置项的学习率。一般偏置项的学习率是权值学习率的两倍。
layer { # 定义了一个卷积层conv1
name: "conv1"
type: "Convolution"
bottom: "data" # 输入blob为data
top: "conv1" # 输出blob为conv1
param {
lr_mult: 1 # 全局学习速率倍乘因子,1表示与全局参数一致
}
param {
lr_mult: 2 # bias学习速率倍乘因子,是全局参数的2倍
}
convolution_param { # 卷积计算参数
num_output: 20 # 输出feature map数量为20
kernel_size: 5 # 卷积核尺寸,5X5
stride: 1 # 卷积输出跳跃间隔,1表示连续输出,无跳跃
weight_filler { # 权值使用xavier填充器
type: "xavier"
}
bias_filler {
type: "constant" # bias使用常数填充器,默认是0
}
}
}
下采样层pool1
layer { # 下采样层pol1,输入conv1,输出pool1
name: "pool1"
type: "Pooling"
bottom: "conv1"
top: "pool1"
pooling_param {
pool: MAX # 最大值下采样法
kernel_size: 2 # 下采样窗口尺寸2X2
stride: 2 # 下采样输出跳跃间隔2X2
}
}
卷积层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"
}
}
}
下采样层pool2
layer {
name: "pool2"
type: "Pooling"
bottom: "conv2"
top: "pool2"
pooling_param {
pool: MAX
kernel_size: 2
stride: 2
}
}
全连接层1
layer { # 全连接层
name: "ip1"
type: "InnerProduct"
bottom: "pool2"
top: "ip1"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
inner_product_param {
num_output: 500 # 该层输出参数 500X500
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
}
}
}
采用ReLU的非线性层
layer { # 非线性层,用ReLU方法
name: "relu1"
type: "ReLU"
bottom: "ip1"
top: "ip1"
}
全连接层2
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"
}
}
}
accuracy层
layer { # 分类准确率层
name: "accuracy"
type: "Accuracy"
bottom: "ip2"
bottom: "label"
top: "accuracy"
include {
phase: TEST
}
}
损失层
layer { # 损失层
name: "loss"
type: "SoftmaxWithLoss" # 采用softmax回归
bottom: "ip2"
bottom: "label"
top: "loss"
}
网络结构图
参考资料:《深度学习-21天实战Caffe》