參考: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