1. 程式人生 > >Caffe學習筆記(六)—— Windows下訓練自己的資料

Caffe學習筆記(六)—— Windows下訓練自己的資料

本文主要介紹:Windows下,根據自己的資料訓練自己的網路模型。

1. 影象資料轉化為lmdb格式

comput_image_mean.bat,生成兩個mldb資料夾:mytrainldb 和 myvalldb;

2.計算訓練樣本均值

(1)編譯caffe-windows-master\tools\ 下的compute_image_mean.cpp,生成compute_image_mean.exe;

    (2)建立comput_image_mean.txt,新增內容:

SET GLOG_logtostderr=1
bin\compute_image_mean.exe  mytrainldb  myimg_mean.binaryproto
pause
第二行有三個引數:

bin\compute_image_mean.exe  :compute_image_mean.exe 路徑

mytrainldb                                 :訓練資料轉化生成的ldb檔案路徑

myimg_mean.binaryproto         :生成的均值檔案路徑

注:

<1> 以上路徑都是相對路徑,需要根據自己的檔案路徑進行設定,對應的絕對路徑為 “comput_image_mean.txt資料夾路徑 + 相對路徑”;

<2>訓練樣本轉化為mldb檔案之前,需要歸一化到同一大小,否則出錯;

3. 網路定義及設定

以 imagenet網路為例,新的caffe安裝包中,沒有imagenet_train.prototxt 和 imagenet_val.prototxt 檔案,網路定義在 caffe-windows-master\models\bvlc_reference_caffenet

中,用到train_val.prototxt 和 solver.prototxt 兩個檔案。

3.1 設定train_val.prototxt 檔案

以下路徑改為對應的訓練資料、均值、測試資料的絕對路徑:



3.2 設定 solver.prototxt 檔案


注:路徑中不能含有中文,同時要注意路徑格式,轉義字元要用 “/” 或“\\”,不能用“\”。

3.3 網路訓練

(1)建立 train_myimg.txt ,新增內容:

SET GLOG_logtostderr=1
..\caffe-windows-master\bin\caffe.exe  train --solver=.\model\solver.prototxt
pause

第二行兩個引數:

..\caffe-windows-master\bin\caffe.exe  :caffe安裝配置時,生成的caffe.exe,在caffe-windows-master\bin 中

train                                                             :表示是進行網路訓練

--solver=.\model\solver.prototxt             : solver.prototxt 檔案檔案路徑

注: 以上路徑都是相對路徑,需要根據自己的檔案路徑進行設定,對應的絕對路徑為 “train_myimg.txt資料夾路徑 + 相對路徑”;

(2) train_myimg.txt 改名為  train_myimg.bat 雙擊執行。

參考: