Caffe 將train與val分開手動進行
1、問題描述:
(1)Linux伺服器上有四塊GTX1080的顯示卡,每塊8G;
(2)現在要微調測試模型InceptionBN_21K,即googlenet v2;
(5)我在微調網路時,將train階段的batch size設定為32,視訊記憶體佔用為6047MiB,無法再上調batch size,否則將會out of memory;
(6)我在(5)的同時,設定test階段的batch size仍為32,於是網路在test時直接out of memory,視訊記憶體佔用超出8G;
2、設定解決方案:
(1)將test階段的batch size降為1,solver.prototxt中test_iter設定為驗證集大小;
(2)將train與test分開進行,手動進行test,過程如下:
a、將train_val.prototxt分為train,prototxt和val.prototxt兩個檔案,分別為訓練網路和測試網路:
將train_val.prototxt中包含TEST的layer刪掉即為train,prototxt;
將train_val.prototxt中包含TRAIN的layer刪掉即為val,prototxt;
b、針對訓練網路,將solver.prototxt改為solverTrain.prototxt,如下:
train_net: "models/InceptionBN_21K_for_Caffe/train.prototxt" display: 1000 average_loss: 40 base_lr: 0.001 lr_policy: "step" stepsize: 200000 gamma: 0.1 max_iter:1000000 weight_decay: 0.0005 momentum: 0.9 snapshot: 1000 snapshot_prefix: "models/InceptionBN_21K_for_Caffe/snapshot/InceptionBN_21K" solver_mode: GPU
即將原有的net替換為train_net;
刪掉test_iter、test_interval及test_initialization欄位,否則會有錯誤報告,可以親測;
此時runtrain.sh檔案只需將引數solver.prototxt改為solverTrain.prototxt;
注:此處存放網路的路徑為: models/InceptionBN_21K_for_Caffe
c、針對測試網路,不需要solver.prototxt檔案,將runtrain.sh改為runVal.sh:
即將原來的train欄位更改為test;./build/tools/caffe test -model models/InceptionBN_21K_for_Caffe/val.prototxt -weights models/InceptionBN_21K_for_Caffe/InceptionBN_21K_iter_100000.caffemodel --iterations=1200 -gpu 2
-solver引數刪掉;
加上-model引數,引數值為a中儲存的val.prototxt檔案;
-weights選擇的是我訓練過程產生的一個caffemodel;
加上--iterations欄位,這裡:iterations × val.prototxt中設定的TEST的batch_size = 你的測試集的大小,如果不設定--iterations,預設迭代次數為50次;
d、執行runVal.sh進行測試