Py-faster-rcnn: error while changing the number of classes

Created on 27 Nov 2015  Â·  12Comments  Â·  Source: rbgirshick/py-faster-rcnn

Hi, I'm trying to use py-faster-rcnn with 2 classes, person and bottle.
However, I got the following error.

I already changed the code in pascal_voc.py at line 28, like

self._classes = ('__background__', # always index 0
                         'bottle', 'person')

And I also changed /models/VGG_CNN_M_1024/faster_rcnn_alt_opt/*train(test).pt

num_classes 21 → 3
bbox_num     84 → 12

After that, I run ./tools/train_faster_rcnn_alt_opt.py --gpu 0 --net_name VGG_CNN_M_1024 --weights data/imagenet_models/VGG_CNN_M_1024.v2.caffemodel --cfg experiments/cfgs/faster_rcnn_alt_opt.yml

However, during learning process, I got this error.

Loaded dataset `voc_2007_trainval` for training
Set proposal method: rpn
Appending horizontally-flipped training examples...
voc_2007_trainval gt roidb loaded from /py-faster-rcnn/data/cache/voc_2007_trainval_gt_roidb.pkl
loading /py-faster-rcnn/output/faster_rcnn_alt_opt/voc_2007_trainval/vgg_cnn_m_1024_rpn_stage1_iter_80000_proposals.pkl
Process Process-3:
Traceback (most recent call last):
  File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
    self.run()
  File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run
    self._target(*self._args, **self._kwargs)
  File "./tools/train_faster_rcnn_alt_opt.py", line 190, in train_fast_rcnn
    roidb, imdb = get_roidb(imdb_name, rpn_file=rpn_file)
  File "./tools/train_faster_rcnn_alt_opt.py", line 68, in get_roidb
    roidb = get_training_roidb(imdb)
  File "/py-faster-rcnn/tools/../lib/fast_rcnn/train.py", line 121, in get_training_roidb
    imdb.append_flipped_images()
  File "/py-faster-rcnn/tools/../lib/datasets/imdb.py", line 103, in append_flipped_images
    boxes = self.roidb[i]['boxes'].copy()
  File "/py-faster-rcnn/tools/../lib/datasets/imdb.py", line 67, in roidb
    self._roidb = self.roidb_handler()
  File "/py-faster-rcnn/tools/../lib/datasets/pascal_voc.py", line 136, in rpn_roidb
    rpn_roidb = self._load_rpn_roidb(gt_roidb)
  File "/py-faster-rcnn/tools/../lib/datasets/pascal_voc.py", line 150, in _load_rpn_roidb
    return self.create_roidb_from_box_list(box_list, gt_roidb)
  File "/py-faster-rcnn/tools/../lib/datasets/imdb.py", line 178, in create_roidb_from_box_list
    overlaps[I, gt_classes[argmaxes[I]]] = maxes[I]
 IndexError: index 9 is out of bounds for axis 1 with size 3

Could you please help?

Most helpful comment

Are you sure to work from scratch, not messing with the cached output of the original voc2007 roidb ?

$ cd <py-faster-rcnn>
$ rm data/cache/voc_2007_trainval_gt_roidb.pkl
$ rm output/faster_rcnn_alt_opt/voc_2007_trainval /vgg_cnn_m_1024_rpn_stage1_iter_80000_proposals.pkl  

All 12 comments

sorry.
I forgot to write this line.

 IndexError: index 9 is out of bounds for axis 1 with size 3

I am having the same issue here. please help

I'm having the same issue.

you should also remove the classes in voc2007 annotations

and also clean the cache

@jojotata have you solve this issue yet?

@mawnja , I removed all object elements with classes I am not interested in, but I still get the same error.

Any suggestion would be appreciated.

Thanks a lot in advance.

Are you sure to use the proper *solver.pt ?
And that solvers redirect properly to your modified *train.pt ?

I have done a tutorial on fine-tuning faster-rcnn for a binary classifier, if that can help.

@deboc I used the script from repo, and I think I used the correct *.pt

Thanks for your tutorial, but I just used the pascal_voc 2007 dataset so I think I only have to modify "'num_classes'" and "num_output" in *.pt, isn't it?

Is there any other possible reason leading to this issue?

Thank you

Are you sure to work from scratch, not messing with the cached output of the original voc2007 roidb ?

$ cd <py-faster-rcnn>
$ rm data/cache/voc_2007_trainval_gt_roidb.pkl
$ rm output/faster_rcnn_alt_opt/voc_2007_trainval /vgg_cnn_m_1024_rpn_stage1_iter_80000_proposals.pkl  

Hi @deboc,

Thank you so much. That should work.

Hi @jojotata - I had the same issue. In my case, it was not able to find the prototxt files. You could try running your train command with the --solver argument which contains the path to the solver file.

same question .....
"Loaded dataset voc_2007_trainval for training
Set proposal method: gt
Appending horizontally-flipped training examples...
Process Process-1:
Traceback (most recent call last)
.......
File "/home/mkl/Documents/mycaffe/py-faster-rcnn/tools/../lib/datasets/pascal_voc.py", line 208, in _load_pascal_annotation
cls = self._class_to_ind[obj.find('name').text.lower().strip()]
....
KeyError:'2':
"

and , I just use pascalVOC to train a modle . so I think it is because my own dataset has somethinh wrong .
So , is there anyone know this error may cased by which part of my own dataset (my dataset has the same construction to pascalVOC)

Was this page helpful?
0 / 5 - 0 ratings