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