分别将cifar10_quick_train_test.prototxt、cifar10_quick_solver.prototxt、train_quick.sh三个文件 copy至自己所建立的文件目录, 如:testCreateLmDB。并修改成自己的文件名:my_quick_train_test.prototxt、my_quick_solver.prototxt、my _train_quick.sh.它们分别是网络结构脚本文件 、超参配置脚本文件 和训练脚本文件。分别修改它们:
a.my_quick_train_test.prototxt网络结构脚本文件
name: "my_quick" #修改成自己的名字
layer {
name: "myimg" #修改成自己的名字
type: "Data"
top: "data"
top: "label"
include {
phase: TRAIN
}
transform_param {
mean_file: "examples/testCreateLmDB/my_mean.binaryproto" #均值所在目录
}
data_param {
source: "examples/testCreateLmDB/my_train_lmdb" #训练数据所在目录
batch_size: 10 #自己的数据量小,修改成10
backend: LMDB
}
}
layer {
name: "myimg"
type: "Data"
top: "data"
top: "label"
include {
phase: TEST
}
transform_param {
mean_file: "examples/testCreateLmDB/my_mean.binaryproto" #均值所在目录
}
data_param {
source: "examples/testCreateLmDB/my_val_lmdb" #测试数据所在目录
batch_size: 10 #自己的数据量小,修改成10
backend: LMDB
}
}
#训练数据采用该网络结构,所以不变,不用修改
.................
.................
layer {
name: "ip2"
type: "InnerProduct"
bottom: "ip1"
top: "ip2"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
inner_product_param {
num_output: 5 #自己的数据只有五类,所以修改成5
weight_filler {
type: "gaussian"
std: 0.1
}
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"
}
b.my_quick_solver.prototxt超参配置脚本文件
# reduce the learning rate after 8 epochs (4000 iters) by a factor of 10
# The train/test net protocol buffer definition
#【1】改为你自己的网络模型配置文件的目录
net: "examples/testCreateLmDB/my_quick_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: 10 #【2】预测阶段迭代次数,我们设为10,这样就可以覆盖我们的100张测试样
# Carry out testing every 500 training iterations.
test_interval: 50 #【3】由于我们只有400张训练样本,所以我们将此改为50,每迭代50次,进行一次测试
# The base learning rate, momentum and the weight decay of the network.
base_lr: 0.001 #【4】权值学习率,其实就是在反向传播阶段,权值每次的调整量的程度
momentum: 0.9
weight_decay: 0.004
# The learning rate policy
lr_policy: "fixed" #【5】在整个过程中,我们使用固定的学习率,当然,你也可以试一下可变学习率
# Display every 100 iterations
display: 20
# The maximum number of iterations
max_iter: 5000
# snapshot intermedate results
snapshot: 4000
snapshot_format: HDF5
snapshot_prefix: "examples/testCreateLmDB/my_quick" #【5】模型存放的位置
# solver mode: CPU or GPU
solver_mode: GPU
c. my _train_quick.sh训练脚本文件
#!/usr/bin/env sh
set -e
TOOLS=./build/tools
$TOOLS/caffe train \
--solver=examples/testCreateLmDB/my_quick_solver.prototxt $@ #注意 该超参数所在的目录
d.训练
在终端caffe目录下执行修改后的训练脚本
./examples/testCreateLmDB/my_train_quick.sh
至此,可以开始训练。
友情提醒:该步骤配置文件 较多,所修改的地方较多,一定要小心,本人在玩这过程中,老出问题。都是目录所在路径没有修改好所造成的。