rbgirshick / py-faster-rcnn

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

How to train a ZF network on one class (person) getting ValueError: could not broadcast input array from shape (4) into shape (0) #52

Open emuchogu opened 8 years ago

emuchogu commented 8 years ago

I'm trying to train a ZF network on one class "person" but I'm getting the following error when I run the code:

File "/home/edward/caffee/r-cnn/faster-rcnn/py-faster-rcnn/tools/../lib/rpn/proposal_target_layer.py", line 138, in _get_bbox_regression_labels bbox_targets[ind, start:end] = bbox_target_data[ind, 1:] ValueError: could not broadcast input array from shape (4) into shape (0)

I initialize the training process by running the following command: ./experiments/scripts/faster_rcnn_end2end.sh 0 ZF

I changed the following files: models/ZF/faster_rcnn_end2end/train.prototxt


name: "ZF" layer { name: 'input-data' type: 'Python' top: 'data' top: 'im_info' top: 'gt_boxes' python_param { module: 'roi_data_layer.layer' layer: 'RoIDataLayer' param_str: "'num_classes': 21" } }

to

name: "ZF" layer { name: 'input-data' type: 'Python' top: 'data' top: 'im_info' top: 'gt_boxes' python_param { module: 'roi_data_layer.layer' layer: 'RoIDataLayer' param_str: "'num_classes': 2" }

}

layer { name: "cls_score" type: "InnerProduct" bottom: "fc7" top: "cls_score" param { lr_mult: 1.0 } param { lr_mult: 2.0 } inner_product_param { num_output: 21 weight_filler { type: "gaussian" std: 0.01 } bias_filler { type: "constant" value: 0 } } }

to

layer { name: "cls_score" type: "InnerProduct" bottom: "fc7" top: "cls_score" param { lr_mult: 1.0 } param { lr_mult: 2.0 } inner_product_param { num_output: 2 weight_filler { type: "gaussian" std: 0.01 } bias_filler { type: "constant" value: 0 } } }


layer { name: "bbox_pred" type: "InnerProduct" bottom: "fc7" top: "bbox_pred" param { lr_mult: 1.0 } param { lr_mult: 2.0 } inner_product_param { num_output: 84 weight_filler { type: "gaussian" std: 0.001 } bias_filler { type: "constant" value: 0 } } }

to

layer { name: "bbox_pred" type: "InnerProduct" bottom: "fc7" top: "bbox_pred" param { lr_mult: 1.0 } param { lr_mult: 2.0 } inner_product_param { num_output: 8 weight_filler { type: "gaussian" std: 0.001 } bias_filler { type: "constant" value: 0 } }

}

I also changed :

lib/datasets/pascal_voc.py Line 28:


    self._classes = ('__background__', # always index 0
                     'person', 'bicycle', 'bird', 'boat',
                     'bottle', 'bus', 'car', 'cat', 'chair',
                     'cow', 'diningtable', 'dog', 'horse',
                     'motorbike', 'person', 'pottedplant',
                     'sheep', 'sofa', 'train', 'tvmonitor')

to

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

I would like to document how to train a faster r-cnn network on a single class, by documenting how a single class is trained I and other should then be able to more easily adapted the code to train multiple classes as well as train using our own data-sets.

wait1988 commented 8 years ago

Have you solved the problem?I just got the same error.

emuchogu commented 8 years ago

Nope. Can you share details on how you have implemented yours, maybe that way we can work on it together and find a solution.

longchuanshu commented 8 years ago

Have you solved the problem?I just got the same error.

shoCaffeTeria commented 8 years ago

I have the same error,too. Could you cope with that? I tryed it with VGG_CNN_M_1024 but it couldn't work. The same error happened.

shoCaffeTeria commented 8 years ago

I think I could solve the error. In pascal_voc.py(202) from cls = self._class_to_ind[obj.find('name').text.lower().strip()] to cls = self._class_to_ind['person']

emuchogu commented 8 years ago

Did changing from cls = self._class_to_ind[obj.find('name').text.lower().strip()] to cls = self._class_to_ind['person']

Work?

On Thu, Mar 17, 2016 at 6:10 AM, shoCaffeTeria notifications@github.com wrote:

I think I could solve the error. In pascal_voc.py(202) from cls = self._class_to_ind[obj.find('name').text.lower().strip()] to cls = self._class_to_ind['person']

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/rbgirshick/py-faster-rcnn/issues/52#issuecomment-197672199

shoCaffeTeria commented 8 years ago

Yes, It worked well.

ednarb29 commented 8 years ago

How can that be handled with more classes and what's with the background class?

JohnnyY8 commented 8 years ago

I have the same error as well. But changing from cls = self._class_to_ind[obj.find('name').text.lower().strip()] to cls = self._class_to_ind['person'] is not good for me. Because I want to train faster r-cnn on DET dataset, can anyone help me ?

macqueen09 commented 8 years ago

same question after I use my own dataset which has 3 class . confused me is that I use this dataset to train a faster RCNN network success last days , after some experience , I come back this train , and It break , I'm confused

tony5614 commented 7 years ago

you can try to remove ./data/cache/voc_2007_trainval_gt_roidb.pkl

find -name "*roidb.pkl" |xargs rm

It works for me

kecaiwu commented 7 years ago

how to solve this error #486 ? @shoCaffeTeria

clvoloshin commented 7 years ago

Check that solver.prototxt points to the correct train/test prototxt