ShaoqingRen / faster_rcnn

Faster R-CNN
Other
2.71k stars 1.22k forks source link

Several errors encountered attempting to train on a single class VOC 2007 #150

Open Espenjt opened 7 years ago

Espenjt commented 7 years ago

Hello. After a week or so of trial and error i have to resort to you smart people to help me out in my attempt to fine-tune F-RCNN on one VOC class.

This issue regards running "script_faster_rcnn_VOC2007_ZF.m" but applies to any dataset. To replicate the original work, i use MATLAB 2014a with CUDA 6.5 on a gtx1080. To start off, i manage to train on the original dataset, with all classes without issues.

  1. Following 1 i reduced the following line in VOCinit.m:

VOCopts.classes={... 'boat'};

and in .\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 * (K+1) (=1) class

input: "bbox_loss_weights"
input_dim: 1  # to be changed on-the-fly to match num ROIs
input_dim: 8 # 4 * (K+1) (=1) class

layer {
    bottom: "fc7"
    top: "cls_score"
    name: "cls_score" ...

    inner_product_param {
        num_output: 2

According to aforementioned issue 1, this should be sufficient to begin training. However, as the annotation-files still contain all classes, thus i run into this MATLAB error while building roidb cache:

roidb (voc_2007_trainval): 1/5011
Error using containers.Map/values
The specified key is not present in this container.

Error in roidb_from_voc>attach_proposals (line 182)
  gt_classes =
  class_to_id.values({voc_rec.objects(valid_objects).class});

I have also here tried to change .\datasets\VOCdevkit2007\VOC2007\ImageSets\Main\test.txt ..\trainval.txt ..\val.txt ..\train.txt to match what is contained in ..\boat_test.txt ..\boat_trainval.txt ..\boat_val.txt ..\boat_test.txt. As these images still contain all the other classes it is to no avail, and the error is still present.

To conquer this, i made a new set of annotations, where i removed all the nodes of the xml annotation files unless the object is named "boat". The caches are then completed, but as i start stage one proposal i run into this error

Preparing training data...Starting parallel pool (parpool) using the 'local' profile ... connected to 4 workers.
Error using proposal_prepare_image_roidb>scale_rois (line 110)
Non-singleton dimensions of the two input arrays must match each other.

Error in
proposal_prepare_image_roidb>@(x,y)compute_targets(conf,scale_rois(gt_rois,im_size,y),gt_labels,x,image_roidb_cell{i},y)
(line 60)
       bbox_targets{i} = cellfun(@(x, y) ...

And here i am at a loss. Any help would be much appreciated

raymondsa commented 7 years ago

Check 'imdb\cache\roidb_voc_2007_train_flip_easy', in my case it was empty, this means can not read the .xml file. Check the XML files format , for parsing the XML annotation files try to replace 'xml2struct.m' with http://www.stat.ucla.edu/~zyyao/data/backup/databaseProject/labelMe/xml2struct.m