参考:https://www.cnblogs.com/denny402/p/5076285.html

首先编译:

make -j8

make pycaffe

 

注:下面的--solver=.... 等价于 -solver ....

########################## -solver:必选参数 ###################
set -e
./build/tools/caffe train
--solver=examples/mnist/lenet_solver.prototxt -gpu 2
#gpu 2表示用第2块gpu运行,如果设置为"-gpu all"表示使用所有的gpu运行

######################-snapshot:可选参数,-gpu:可选参数 #############
#加上断点的训练
set -e
./build/tools/caffe train
--solver=examples/mnist/lenet_solver.prototxt \
--snapshot=examples/mnist/snapshot/lenet_solver_iter_400.solverstate

######################## -weights:可选参数 #################
#用预先训练好的权重来fine-tuning模型,需要一个caffemodel,不能和-snapshot同时使用
set -e
./build/tools/caffe train
--solver=examples/mnist/lenet_solver.prototxt \
#这里放训练好的模型参数caffemodel
--weights=models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel

########### test参数用在测试阶段,用于最终结果的输出,要配置模型中设定输入accuracy或loss,若我们在验证集中已训练好模型,则可以这么写(用caffe自带的测试方法)###################################

./build/tools/caffe test --model=examples/mnist/lenet_train_test.prototxt \
--weights=examples/mnist/lenet_iter_10000.caffemodel -gpu 0 -iterations 100

############## time参数在屏幕上显示程序运行时间 ##################
###########可以在屏幕上显示lenet模型迭代10次所用的时间,包括每次迭代的forward和backward所用的时间##############
############也包括每层forward和backward所用的平均时间###################
./build/tools/caffe time --model=examples/mnist/lenet_train_test.prototxt -gup 0 -iterations 10

########### 利用给定的权重,利用第一块gpu,迭代10次lenet模型所用的时间 #################
./build/tools/caffe time --model=examples/mnist/lenet_train_test.prototxt \
--weights=examples/mnist/lenet_iter_10000.caffemodel -gpu 0 -iterations 10

############### device_query参数诊断gpu信息 ##############
./build/tools/caffe device_query -gpu 0

################# 2个关于gpu的例子 #####################
./build/tools/caffe train --solver=examples/mnist/lenet_solver.prototxt -gpu 0,1
./build/tools/caffe train --solver=examples/mnist/lenet_solver.prototxt -gpu all
#这2个例子说明:用2块或多块GPU来平行运算,速度会快很多;但是如果只有1块或没有GPU,就不要加-gpu参数了,加了反而更慢

#######最后在linux下本身就有1个time命令,因此可以结合使用,因此运行mnist例子的最终命令(1块GPU)############
sudo time ./build/tools/caffe train --solver=examples/mnist/lenet_solver.prototxt