Original Source : Alex’s CIFAR-10 tutorial
本文以CIFAR-10数据集为例,对Caffe的train及test操作进行简单说明:
1. solver.prototxt 以及 cifar10_full_train_test.prototxt 区别:
CIFAR-10其训练网络配置文件与测试网络配置文件是同一个 cifar10_full_train_test.prototxt 文件。
常规情况下,像model文件夹下的AlexNet中出现三个.prototxt 文件,其中 train_val.prototxt 与之类似。
而solver.prototxt是包含全局参数的配置文件,主要用于train以及fine-tuning,在test时是不需要的。
2. cifar10_full_train_test.prototxt 中的数据输入:
layer {
name: "cifar"
type: "Data"
top: "data"
top: "label"
include {
phase: TRAIN
}
transform_param {
mean_file: "examples/cifar10/mean.binaryproto"
}
data_param {
source: "examples/cifar10/cifar10_train_lmdb"
batch_size: 100
backend: LMDB
}
}
layer {
name: "cifar"
type: "Data"
top: "data"
top: "label"
include {
phase: TEST
}
transform_param {
mean_file: "examples/cifar10/mean.binaryproto"
}
data_param {
source: "examples/cifar10/cifar10_test_lmdb"
batch_size: 100
backend: LMDB
}
}
正如1中所说,在这里定义train以及test的输入数据的路径。
3. cifar10_quick_solver.prototxt 说明:
# Carry out testing every 500 training iterations.
test_interval: 500
每500次训练迭代进行一次验证测试(validation),并不是一直训练到结束后才进行测试(test)。# snapshot intermediate results
snapshot: 4000
snapshot_format: HDF5
如果保留 snapshot_format: HDF5会生成.h5后缀的快照,用于继续训练或者 fine-tuning。
如果注释掉该语句,会生成.caffemodel后缀权值文件,用于继续训练,fine-tuning,或者test。
4. 训练:
caffe train \
--solver=examples/cifar10/cifar10_quick_solver.prototxt
网络结构在 cifar10_quick_solver.prototxt 文件中指向了:
net: "examples/cifar10/cifar10_quick_train_test.prototxt"
caffe train \
--solver=examples/cifar10/cifar10_quick_solver_lr1.prototxt \
--snapshot=examples/cifar10/cifar10_quick_iter_4000.solverstate.h5
利用的是4000次迭代后的快照.h56. 测试:
sudo caffe test \
--model=./examples/cifar10/cifar10_train_test.prototxt --weights=./examples/cifar10/cifar10_quick_iter_5000.caffemodel --iterations 100 -gpu all
使用所有的GPU
加载之前5000次迭代后获得的model