1.训练脚本或接口
#!/usr/bin/env sh
set -e
./build/tools/caffe train --solver=examples/mnist/lenet_solver.prototxt $@
//set -e
//告诉bash如果任何语句的执行结果不是true则应该退出。这样的好处是防止错误像滚雪球般变大导致一个致命的错误,而这些错误本应该在之前就被处理掉。如果要增加可读性,可以使用set -o errexit,它的作用与set -e相同。
//$@
//表示统计参数个数
如果需要将caffe训练的屏幕信息打印到指定文件中,使用如下脚本train.sh
#!/usr/bin/env sh
#删除已有的log文件
log_file=~/tmp/train.log
rm -vf $log_file
#运行caffe train.sh,并将屏幕信息结果保存到指定的log_file文件中
# Train mnist
sh examples/mnist/train_lenet.sh 2>&1 | tee $log_file
train.sh在caffe根目录下调用命令:
$ sh train.sh
2.solver配置文件
# The train/test net protocol buffer definition
net: "examples/mnist/lenet_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: 100
# Carry out testing every 500 training iterations.
test_interval: 500
# The base learning rate, momentum and the weight decay of the network.
base_lr: 0.01
momentum: 0.9
weight_decay: 0.0005
# The learning rate policy
lr_policy: "inv"
gamma: 0.0001
power: 0.75
# Display every 100 iterations
display: 100
# The maximum number of iterations
max_iter: 10000
# snapshot intermediate results
snapshot: 5000
snapshot_prefix: "examples/mnist/lenet"
# solver mode: CPU or GPU
solver_mode: GPU