【深度學習】之Caffe的solver文件配置(轉載自csdn) Solver.prototxt 流程 solver參數 FCN的solver.prototxt文件
2的博客 - 博客頻道 - CSDN.NET
今天在做FCN實驗的時候,發現solver.prototxt文件一直用的都是model里自帶的,一直都對裡面的參數不是很了解,所以今天認真學習了一下裡面各個參數的意義。
DL的任務中,幾乎找不到解析解,所以將其轉化為數學中的優化問題。sovler的主要作用就是交替調用前向傳導和反向傳導 (forward & backward) 來更新神經網路的連接權值,從而達到最小化loss,實際上就是迭代優化演算法中的參數。
Caffe的solver類提供了6種優化演算法,配置文件中可以通過type關鍵字設置:
- Stochastic Gradient Descent (type: 「SGD」)
- AdaDelta (type: 「AdaDelta」)
- Adaptive Gradient (type: 「AdaGrad」)
- Adam (type: 「Adam」)
- Nesterov』s Accelerated Gradient (type: 「Nesterov」)
- RMSprop (type: 「RMSProp」)
簡單地講,solver就是一個告訴caffe你需要網路如何被訓練的一個配置文件。
Solver.prototxt 流程
- 首先設計好需要優化的對象,以及用於學習的訓練網路和測試網路的prototxt文件(通常是train.prototxt和test.prototxt文件)
- 通過forward和backward迭代進行優化來更新參數
- 定期對網路進行評價
- 優化過程中顯示模型和solver的狀態
solver參數
base_lr
這個參數代表的是此網路最開始的學習速率(Beginning Learning rate),一般是個浮點數,根據機器學習中的知識,lr過大會導致不收斂,過小會導致收斂過慢,所以這個參數設置也很重要。
lr_policy
這個參數代表的是learning rate應該遵守什麼樣的變化規則,這個參數對應的是字元串,選項及說明如下:
- 「step」 - 需要設置一個stepsize參數,返回base_lr * gamma ^ ( floor ( iter / stepsize ) ),iter為當前迭代次數
- 「multistep」 - 和step相近,但是需要stepvalue參數,step是均勻等間隔變化,而multistep是根據stepvalue的值進行變化
- 「fixed」 - 保持base_lr不變
- 「exp」 - 返回base_lr * gamma ^ iter, iter為當前迭代次數
- 「poly」 - 學習率進行多項式誤差衰減,返回 base_lr ( 1 - iter / max_iter ) ^ ( power )
- 「sigmoid」 - 學習率進行sigmod函數衰減,返回 base_lr ( 1/ 1+exp ( -gamma * ( iter - stepsize ) ) )
gamma
這個參數就是和learning rate相關的,lr_policy中包含此參數的話,需要進行設置,一般是一個實數。
stepsize
This parameter indicates how often (at some iteration count) that we should move onto the next 「step」 of training. This value is a positive integer.
stepvalue
This parameter indicates one of potentially many iteration counts that we should move onto the next 「step」 of training. This value is a positive integer. There are often more than one of these parameters present, each one indicated the next step iteration.
max_iter
最大迭代次數,這個數值告訴網路何時停止訓練,太小會達不到收斂,太大會導致震蕩,為正整數。
momentum
上一次梯度更新的權重,real fraction
weight_decay
權重衰減項,用於防止過擬合。
solver_mode
選擇CPU訓練或者GPU訓練。
snapshot
訓練快照,確定多久保存一次model和solverstate,positive integer。
snapshot_prefix
snapshot的前綴,就是model和solverstate的命名前綴,也代表路徑。
net
path to prototxt (train and val)
test_iter
每次test_interval的test的迭代次數,假設測試樣本總數為10000張圖片,一次性執行全部的話效率很低,所以將測試數據分為幾個批次進行測試,每個批次的數量就是batch_size。如果batch_size=100,那麼需要迭代100次才能將10000個數據全部執行完,所以test_iter設置為100。
test_interval
測試間隔,每訓練多少次進行一次測試。
display
間隔多久對結果進行輸出
iter_size
這個參數乘上train.prototxt中的batch size是你實際使用的batch size。 相當於讀取batchsize * itersize個圖像才做一下gradient decent。 這個參數可以規避由於gpu內存不足而導致的batchsize的限制 因為你可以用多個iteration做到很大的batch 即使單次batch有限。
average_loss
取多次foward的loss作平均,進行顯示輸出。
FCN的solver.prototxt文件
推薦閱讀: