LeNet-5模型prototxt檔案描述及各層含義、註釋
阿新 • • 發佈:2018-12-12
LeNet-5模型描述
本節例程中的LeNet-5模型與原版稍有不同(例如,將Sigmoid啟用函式改為ReLU),其描述檔案在Caffe目錄下的examples/mnist/lenet_train_test.prototxt
中,內容及程式碼註釋如下:
name: "LeNet" //網路(Net)的名稱為LeNet
layer { //定義一個層(Layer)
name: "mnist" //層的名稱為mnist
type: "Data" //層的型別為資料層
top: "data" //層的輸出blob有兩個:data和label
top: "label"
include {
phase: TRAIN //該層引數只在訓練階段有效
}
transform_param {
scale: 0.00390625 //資料變換使用的資料縮放因子
}
data_param { //資料層引數
source: "examples/mnist/mnist_train_lmdb" //LMDB的路徑
batch_size: 64 // 批量數目,一次讀取64張圖
backend: LMDB // 資料格式為LMDB
}
}
layer {
name: "mnist"
type: "Data"
top: "data"
top: "label"
include {
phase: TEST
}
transform_param {
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
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: "accuracy"
type: "Accuracy"
bottom: "ip2"
bottom: "label"
top: "accuracy"
include {
phase: TEST
}
}
layer {
name: "loss"
type: "SoftmaxWithLoss"
bottom: "ip2"
bottom: "label"
top: "loss"
}
注:(本文引用自書籍《深度學習——21天實戰Caffe》,趙永科著,中國工信出版集團&電子工業出版社出版)本文內容僅供參考;