Caffe 命令列解析

2021-08-01 20:29:36 字數 2823 閱讀 4615

#sudo sh ./build/tools/caffe train --solver=examples/mnist/train_lenet.sh
caffe程式命令列執行格式如下:

caffe

其中有這樣四種:

#./build/tools/caffe train -solver examples/mnist/lenet_solver.prototxt
-gpu可選引數。該引數用來指定用那一快gpu執行,根據gpu的id進行選擇,如果設定為『gpu all』則使用所有的gpu進行執行。如果使用第二快gpu執行。

#./build/tools/caffe train -solver examples/mnist/lenet_solver.prototxt -gpu 2
-snapshot:可選引數。該引數用來從快照中恢復訓練。可以在solver配置檔案設定快照,儲存solverstate。如:

#./build/tools/caffe train -solver examples/mnist/lenet_solver.prototxt -snapshot examples/mnist/lenet_iter_5000.solverstate
-weight:可選引數。用預先訓練好的權重來fine-tuning模型,需要乙個caffemodel,不能和-snapshot同時使用。如:

# ./build/tools/caffe train -solver examples/finetuning_on_flicker_style.prototxt -weights models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel
-iteration: 可選引數,迭代次數,預設為50。如果在配置檔案中沒有設定迭代次數,則預設迭代50次

-model: 可選引數,定義在protocol buffer檔案中的模型。也可以在solver配置檔案中指定

-sighup_effect: 可選引數。用來設定當程式發生掛起事件時,執行的操作,可以設定為snapshot,stop或none,預設為snapshot

-sigint_effect: 可選引數。用來設定當程式鍵盤中止事件時(ctrl+c),執行的操作,可以設定為snapshot,stop或none,預設為stop

剛才舉例來一些train引數例子,現在我們看其他三個

test引數在測試階段,用於最終結果輸出,要模型配置檔案中我們可以設定需要輸入accuracy還是loss。假設我們要在驗證集中驗證已經訓練好的模型,就可以這樣寫。

# ./build/tools/caffe test -model examples/mnist/lenet_train_test.prototxt -weights examples/mnist/lenet_iter_10000.caffemodel -gpu 0 iterrations 100
這個例子比較長,不僅用到了test引數,還用到了-model, -weights, -gpu和-iteration四個引數。意思是利用訓練好了的權重(-weight),輸入到測試模型中(-model),用編號為0的gpu(-gpu)測試100次(-iteration)。

time 引數用來在螢幕上顯示執行時間。如:

# ./build/tools/caffe time -model examples/mnist/lenet_train_test.prototxt -iterations 10
這個例子用來在螢幕上顯示lenet模型迭代10次所使用的時間。包括每次迭代的forward和backward所用的時間,也包括每層forward和backward所用的平均時間。

# ./build/tools/caffe time -model examples/mnist/lenet_train_test.prototxt -gpu -0
這個例子用來顯示lenet模型用gpu迭代50次所使用的時間。

# ./build/tools/caffe time -model examples/mnist/lenet_train_test.prototxt -weights examples/mnist/lenet_iter_10000.caffemodel -gpu 0 iterations 10
利用給定的權重,利用第一塊gpu,迭代10次lenet模型所用的時間

device_query 引數用來診斷gpu資訊

# .build/tools/caffe device_query -gpu 0
最後,看兩個關於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

這兩個例子表示: 用兩塊或多塊gpu來平行運算,這樣速度會快很多。但是如果你只有一塊或沒有gpu, 就不要加-gpu引數了,加了反而慢。

在linux下,本身就有乙個time命令,因此可以結合進來使用,因此我們執行mnist例子最終命令為

sudo time ./build/tools/caffe train -solver examples/mnist/lenet_solver.prototxt

caffe命令列解析

caffe提供三種介面,一般是c python matlab。一般可執行檔案都是放在 build tools 資料夾內,在命令列執行命令必須現在該目錄下。也有可能不在說不定在別的地方,找caffe.exe就對了 caffe的命令形式如下 caffe 其中的command有這樣四種 其中的args引數...

Caffe學習 命令列解析

caffe的執行提供三種介面 c 介面 命令列 python介面和matlab介面。本文先對命令列進行解析,後續會依次介紹其它兩個介面。caffe的c 主程式 caffe.cpp 放在根目錄下的tools資料夾內,當然還有一些其它的功能檔案,如 convert imageset.cpp,train ...

caffe基礎 7 命令列解析

caffe的執行提供三種介面 c 介面 命令列 python介面和matlab介面。本文先對命令列進行解析,後續會依次介紹其它兩個介面。caffe的c 主程式 caffe.cpp 放在根目錄下的tools資料夾內,當然還有一些其它的功能檔案,如 convert imageset.cpp,train ...