1. 程式人生 > >caffe下的finetune訓練

caffe下的finetune訓練

              之前用了caffe訓練了一些資料,之後打算用finetune訓練,其實finetune的本質就是用你已經有的引數檔案來初始化(就是之前訓練好的caffemodel),而直接訓練的初始化是按照網路定義指定的方式初始化(如高斯隨機初始化)。這樣的好處就是在訓練的時候可以很快的收斂並達到很好的效果,所以這種情況下所需要的樣本數量和迭代次數都可以不大,而且可以隨意的設定你想要分類的數量,下面就具體介紹如何進行finetune.

         1)首先要更改網路設定,在prototxt裡將最後一層的名字隨便更改為你想要的,更改最後一層的輸出數量,如下例項:

         

     


              2)solver prototxt裡減少學習率base_lr,一般為0.001,增大新加入層的lr_mult,The idea is to have the rest of the model change very slowly with new data, but let the new layer learn fast. we set`stepsize` in the solver to a lower value than if we were training from scratch, since we're virtually far along in training and therefore want the learning rate to go down faster.

Note that we could also entirely prevent fine-tuning of all layers other than `fc8_flickr` by setting their`lr_mult` to 0.

       3)用自帶的create_imagenet.sh指令碼生成訓練和驗證資料,用make_imagenet_mean.sh生成均值檔案,當然也要在solver.prototxt和train.prototxt裡設定上面兩個檔案的路徑,為當初設定的是相對路徑,結果訓練的時候找不到這些檔案,後來設定的絕對路徑就可以了

       4)執行訓練:

 ./build/tools/caffe train -solver models/finetune_flickr_style/solver.prototxt -weights models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel -gpu 0

如果使用cpu模式,那麼最後的-gpu省略