caffe学习日记--lesson4:windows下caffe DEMO (mnist and cifar10)
1.下载数据
mnist官网:http://yann.lecun.com/exdb/mnist/
2.数据格式转化
使用编译得到的convent_mnist_data.exe程序,得到lmdb格式的数据(lmdb的内存消耗是leveldb的1.1倍,但是lmdb的速度比leveldb快10%至15%,重要的是lmdb允许多种训练模型同时读取同一组数据集。 )
..\..\Build\x64\Release\convert_mnist_data.exe train-images.idx3-ubyte train-labels.idx1-ubyte .\lmdb\train_lmdb
..\..\Build\x64\Release\convert_mnist_data.exe t10k-images.idx3-ubyte t10k-labels.idx1-ubyte .\lmdb\test_lmdb
pause
简单说明:exe 数据 标签 保存的到文件 (其中lmdb目录实现建立好)
..\ 相对路径回到上一级目录
.\
当前目录下,
3.配置文件的编写
3.1 lenet_train_test.prototxt
name: "LeNet"
layer {
name: "mnist"
type: "Data"
top: "data"
top: "label"
include {
phase: TRAIN
}
transform_param {
scale: 0.00390625
}
data_param {
source: "../../data/mnist/lmdb/train_lmdb"
batch_size: 64
backend: LMDB
}
}
layer {
name: "mnist"
type: "Data"
top: "data"
top: "label"
include {
phase: TEST
}
transform_param {
scale: 0.00390625
}
data_param {
source: "../../data/mnist/lmdb/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"
}
3.2 lenet_solver.prototxt
net: "lenet_train_test.prototxt"
test_iter: 100
test_interval: 500
base_lr: 0.01
momentum: 0.9
weight_decay: 0.0005
lr_policy: "inv"
gamma: 0.0001
power: 0.75
display: 100
max_iter: 10000
snapshot: 5000
snapshot_prefix: "./models/lenet"
solver_mode: GPU
3.3 bat
..\..\Build\x64\Release\caffe train --solver=lenet_solver.prototxt
pause
具体语法参考:http://www.cnblogs.com/denny402/tag/caffe/
作为学术研究人员,应当熟练书写各种prototxt文件。
4.训练
注意bat文件和solver.prototxt,lenet_train_test.prototxt 文件放在同一级目录,且新建文件夹models用来保存caffemodel
运行bat,即可训练模型,得到caffemodel