深度學習Caffe實戰筆記(20)Windows平臺 Faster-RCNN 訓練自己的資料集
1、把自己的資料集放到Faster-master中
我覺得這個過程是最重要的一個過程吧,博主在這裡跳了很多的坑,最後找到了一個非常簡單高效的方法。不用修改任何檔案,就可以輕鬆實現載入自己的資料集。
在faster_rcnn-master資料夾下,有一個datasets資料夾,把VOCdevkit2007資料夾放在datasets資料夾下,然後在VOCdevkit2007資料夾下把你的資料集資料夾拷進去,並把你的資料集資料夾命名為VOC2007。通過這種方式可以最大限度的減少路徑修改的麻煩。當然,如果你不想這樣做,就需要修改faster_rcnn-master\datasets\VOCdevkit2007\VOCcode\VOCinit.m
不採用命名VOC2007的方法就要把這幾個路徑修改成自己的路徑。
2、修改資料標籤
在faster_rcnn-master\datasets\VOCdevkit2007\VOCcode\VOCinit.m中把標籤修改成自己的標籤
if VOC2006
% VOC2006 classes
VOCopts.classes={...
'bicycle'
'bus'
'car'
'cat'
'cow'
'dog'
'horse'
'motorbike'
'person'
'sheep'};
else
% VOC2007 classes
VOCopts.classes={...
'person' %修改成自己的標籤
};
end
3、修改驗證引數
function\fast_rcnn\fast_rcnn_train.m和function\rpn\proposal_train.m中,
ip.addParamValue('val_iters', 56, @isscalar); %原來的值是500
ip.addParamValue('val_interval' , 2000, @isscalar);
據說這個地方是根據資料集來的,是驗證集的1/5,博主沒有試過不修改是什麼情況,感興趣的同學可以不修改對比有什麼差別。
4、網路模型引數的修改
models\ fast_rcnn_prototxts\ZF\ train_val.prototxt models檔案中預設的應該是空資料夾,這個模型大小1.4G,我沒法上傳,所以大家先去網上找找下載一下,如果找不到聯絡我我再把需要的檔案發給你。
input: "bbox_targets"
input_dim: 1 # to be changed on-the-fly to match num ROIs
input_dim: 8 # 根據類別數改,該值為(類別數+1)*4
input_dim: 1
input_dim: 1
input: "bbox_loss_weights"
input_dim: 1 # to be changed on-the-fly to match num ROIs
input_dim: 8 # 根據類別數改,該值為(類別數+1)*4
input_dim: 1
input_dim: 1
layer {
bottom: "fc7"
top: "cls_score"
name: "cls_score"
param {
lr_mult: 1.0
}
param {
lr_mult: 2.0
}
type: "InnerProduct"
inner_product_param {
num_output: 2 #根據類別數改該值為類別數+1
layer {
bottom: "fc7"
top: "bbox_pred"
name: "bbox_pred"
type: "InnerProduct"
param {
lr_mult: 1.0
}
param {
lr_mult: 2.0
}
inner_product_param {
num_output: 8 #根據類別數改,該值為(類別數+1)*4
faster_rcnn-master\models\fast_rcnn_prototxts\ZF\test.prototxt
layer {
bottom: "fc7"
top: "cls_score"
name: "cls_score"
param {
lr_mult: 1.0
}
param {
lr_mult: 2.0
}
type: "InnerProduct"
inner_product_param {
num_output: 2 #根據類別修改!類別數+1
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
value: 0
}
}
}
layer {
bottom: "fc7"
top: "bbox_pred"
name: "bbox_pred"
type: "InnerProduct"
param {
lr_mult: 1.0
}
param {
lr_mult: 2.0
}
inner_product_param {
num_output: 8 #根據類別修改!(類別數+1)*4
weight_filler {
type: "gaussian"
std: 0.001
}
bias_filler {
type: "constant"
value: 0
}
}
}
models\ fast_rcnn_prototxts\ZF_fc6\ train_val.prototxt
input: "bbox_targets"
input_dim: 1 # to be changed on-the-fly to match num ROIs
input_dim: 8 # 4*(類別數+1) 因為我只標註了一個類
input_dim: 1
input_dim: 1
input: "bbox_loss_weights"
input_dim: 1 # to be changed on-the-fly to match num ROIs
input_dim: 8 # 4*(類別數+1)
input_dim: 1
input_dim: 1
layer {
bottom: "fc7"
top: "cls_score"
name: "cls_score"
param {
lr_mult: 1.0
}
param {
lr_mult: 2.0
}
type: "InnerProduct"
inner_product_param {
num_output: 2 #類別數+1
layer {
bottom: "fc7"
top:"bbox_pred"
name:"bbox_pred"
type:"InnerProduct"
param {
lr_mult:1.0
}
param {
lr_mult:2.0
}
inner_product_param{
num_output: 8 #(類別數+1)*4
models\ fast_rcnn_prototxts\ZF_fc6\ test.prototxt
layer {
bottom: "fc7"
top: "cls_score"
name: "cls_score"
param {
lr_mult: 1.0
}
param {
lr_mult: 2.0
}
type: "InnerProduct"
inner_product_param {
num_output: 2 類別數+1
layer {
bottom: "fc7"
top: "bbox_pred"
name: "bbox_pred"
type: "InnerProduct"
param {
lr_mult: 1.0
}
param {
lr_mult: 2.0
}
inner_product_param {
num_output: 8 #(類別數+1) *4
5、solver檔案的更改
solver檔案的更改在faster_rcnn-master\experiments+Model\ZF_for_Faster_RCNN_VOC2007.m
model.stage1_rpn.solver_def_file = fullfile(pwd, 'models', 'rpn_prototxts', 'ZF', 'solver_30k40k.prototxt'); %solver_60k80k.prototxt可以修改不同的solver檔案
model.stage1_rpn.test_net_def_file = fullfile(pwd, 'models', 'rpn_prototxts', 'ZF', 'test.prototxt');
model.stage1_rpn.init_net_file = model.pre_trained_net_file;
6、開始訓練
開啟faster_rcnn-master\experiments\script_faster_rcnn_VOC2007_ZF.m,切換到faster_rcnn-master目錄,開始訓練。
補充:
如果出現測試精度為0的情況,需要在imdb\imdb_eval_voc.m中做以下修改
%do_eval = (str2num(year) <= 2007) | ~strcmp(test_set,'test');
do_eval = 1;