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

Created on 4 Jan 2016  Â·  13Comments  Â·  Source: rbgirshick/py-faster-rcnn

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.

Most helpful comment

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

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

It works for me

All 13 comments

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

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

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

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.

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']

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 [email protected]
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

Yes, It worked well.

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

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 ?

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

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

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

It works for me

how to solve this error #486 ? @shoCaffeTeria

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

Was this page helpful?
0 / 5 - 0 ratings