rbgirshick / py-faster-rcnn

Faster R-CNN (Python implementation) -- see https://github.com/ShaoqingRen/faster_rcnn for the official MATLAB version
Other
8.14k stars 4.11k forks source link

Error Training on 4 classes #316

Open Sai-Manikantha opened 8 years ago

Sai-Manikantha commented 8 years ago

Hi all, I am trying to train py-faster-rcnn network on PASCAL VOC 2007 dataset on 4 classes. I have changed the classes variable in pascal_voc.py and I have also made proper changes in train and test prototxt files. But I am getting the following error while training. Did anyone encounter a similar problem? Any help would be appreciated.

Log is as below:

Number of classes : 4 Loaded dataset voc_2007_trainval for training Set proposal method: gt Appending horizontally-flipped training examples... objs : [<Element 'object' at 0x7fe2660a85d0>, <Element 'object' at 0x7fe2660a8850>, <Element 'object' at 0x7fe2660a8d50>] Traceback (most recent call last): File "./tools/train_net.py", line 104, in imdb, roidb = combined_roidb(args.imdb_name) File "./tools/train_net.py", line 69, in combined_roidb roidbs = [get_roidb(s) for s in imdb_names.split('+')] File "./tools/train_net.py", line 66, in get_roidb roidb = get_training_roidb(imdb) File "/home/sai/py-faster-rcnn/tools/../lib/fast_rcnn/train.py", line 118, in get_training_roidb imdb.append_flipped_images() File "/home/sai/py-faster-rcnn/tools/../lib/datasets/imdb.py", line 106, in append_flipped_images boxes = self.roidb[i]['boxes'].copy() File "/home/sai/py-faster-rcnn/tools/../lib/datasets/imdb.py", line 67, in roidb self._roidb = self.roidb_handler() File "/home/sai/py-faster-rcnn/tools/../lib/datasets/pascal_voc.py", line 111, in gt_roidb for index in self.image_index] File "/home/sai/py-faster-rcnn/tools/../lib/datasets/pascal_voc.py", line 217, in _load_pascal_annotation cls = self._class_to_ind[obj.find('name').text.lower().strip()] KeyError: 'chair'

karaspd commented 8 years ago

You probably need to write some line of codes to ignore any objects with classes except the classes you are looking for when you are loading the annotation _load_pascal_annotation. Something like cls_objs = [ obj for obj, clas in objs, self._classes if obj.find('name').text== clas]

jhsonn commented 8 years ago

@Sai-Manikantha Did you solve your error? Hi, I'm also trying to train only 5 classes in PASCAL VOC 2007 dataset. Exactly same error occured here. Can anybody please give me a advice? I modified /lib/datasets/pascal_voc.py and proper prototext files. Both faster_rcnn_alt_opt and faster_rcnn_end2end produce same error.

Modifications I made is below: /lib/datasets/pascal_voc.py , line 31) self._classes = ('background', # always index 0 bicycle', 'cat', 'dog', 'person')

(in case of using faster_rcnn_end2end and ZF network) /models/pascal_voc/ZF/faster_rcnn_end2end/train.prototxt num_classes in "input-data" : 21 to 5 num_output in "cls_score" : 21 to 5 num_output in "bbox_pred" : 84 to 20 (same modification applied to test.prototxt)

Command I used : "./experiments/scripts/faster_rcnn_end2end.sh 0 ZF pascal_voc" Log is below:

Stuck this error more than a week.. Any kind of help would be appreciated. Thanks!

Sai-Manikantha commented 8 years ago

@karaspd I'm sorry for the late reply. Thank you so much for your help. I added some code as you suggested. Now I am able to train PASCAL VOC dataset on 4 classes.

Sai-Manikantha commented 8 years ago

@jhsonn Hi !! You can follow the steps suggested by @karaspd. Please feel free to post if it doesn't work for you.

    cls_objs = [obj for obj, clas in objs, self._classes if obj.find('name').text== clas]
    objs = cls_objs
jhsonn commented 8 years ago

@Sai-Manikantha Hi, I modified pascal_voc.py as you posted but it still doesn't work..

File "./tools/train_net.py", line 104, in imdb, roidb = combined_roidb(args.imdb_name) File "./tools/train_net.py", line 69, in combined_roidb roidbs = [get_roidb(s) for s in imdb_names.split('+')] File "./tools/train_net.py", line 66, in get_roidb roidb = get_training_roidb(imdb) File "/home/hope/jhson/caffe/py-faster-rcnn2/tools/../lib/fast_rcnn/train.py", line 118, in get_training_roidb imdb.append_flipped_images() File "/home/hope/jhson/caffe/py-faster-rcnn2/tools/../lib/datasets/imdb.py", line 106, in append_flipped_images boxes = self.roidb[i]['boxes'].copy() File "/home/hope/jhson/caffe/py-faster-rcnn2/tools/../lib/datasets/imdb.py", line 67, in roidb self._roidb = self.roidb_handler() File "/home/hope/jhson/caffe/py-faster-rcnn2/tools/../lib/datasets/pascal_voc.py", line 103, in gt_roidb for index in self.image_index] File "/home/hope/jhson/caffe/py-faster-rcnn2/tools/../lib/datasets/pascal_voc.py", line 184, in _load_pascal_annotation cls_objs = [obj for obj, clas in objs, self._classes if obj.find('name').text== clas] ValueError: too many values to unpack

Above is my error message. Can you tell me more detail about modification you made? (like which line of code you modified and how) I'm not sure where to put "cls_objs=[obj for....]" and what to delete. Thanks in advance! I really hope someday I can train this model without any error..

Sai-Manikantha commented 8 years ago

Hi @jhsonn, when you are loading the annotation in _load_pascal_annotation method, look for something like objs = diff_objs (or non_diff_objs) After that line insert something similar to below code

cls_objs = [obj for obj in objs if obj.find('name').text in self._classes]
objs = cls_objs

Hope this helps.

jhsonn commented 8 years ago

@Sai-Manikantha Thank you so much for your help! I've done training without any error. Thanks again.

Po-Hsuan-Huang commented 7 years ago

@jhsonn

I think your first problem is that you forgot to delete the plk file in /data/cache folder. The program reads the already generated data table from cache to increase speed. That is the only reason I can think of why you get a class that is not in self._classes.

@karaspd

cls_objs = [obj for obj in objs if obj.find('name').text in self._classes] objs = cls_objs Only returns cls_objs in self._classes. What causes ojbs get classes not defined in self._classes ?

Thanks

pasonx commented 7 years ago

@jhsonn Hi friend, can you tell me how do you debug your error? thanks so much

zhilaAI commented 5 years ago

Hi guys I have the same problem but for test data set. Can anybody help me how to solve it?

VOC07 metric? Yes Traceback (most recent call last): File "./tools/test_net.py", line 120, in <module> test_net(sess, net, imdb, filename, max_per_image=args.max_per_image) File "/home/zhila/Seal_detection/tf-faster-rcnn/tools/../lib/model/test.py", line 192, in test_net imdb.evaluate_detections(all_boxes, output_dir) File "/home/zhila/Seal_detection/tf-faster-rcnn/tools/../lib/datasets/pascal_voc.py", line 279, in evaluate_detections self._do_python_eval(output_dir) File "/home/zhila/Seal_detection/tf-faster-rcnn/tools/../lib/datasets/pascal_voc.py", line 242, in _do_python_eval use_07_metric=use_07_metric, use_diff=self.config['use_diff']) File "/home/zhila/Seal_detection/tf-faster-rcnn/tools/../lib/datasets/voc_eval.py", line 137, in voc_eval R = [obj for obj in recs[imagename] if obj['name'] == classname] KeyError: '0802_100_Seal__PB_003' Command exited with non-zero status 1 48.71user 10.26system 1:15.89elapsed 77%CPU (0avgtext+0avgdata 3046436maxresident)k 99264inputs+3376outputs (0major+715410minor)pagefaults 0swaps

shirleyatgithub commented 3 years ago

@zhilaAI Hi, I have encountered the same error as yours. Have you solved this problem? could you tell me how to ?