unsky / FPN

Feature Pyramid Networks for Object Detection
524 stars 263 forks source link

TypeError: slice indices must be integers or None or have an __index__ method #104

Open zh583007354 opened 5 years ago

zh583007354 commented 5 years ago

Hello, I have some problems when running the codes on coco. Maybe you can solve it easily. Thank you very much. Traceback (most recent call last), File "./tools/train_net.py", line 112, in max_iters=args.max_iters) File "/home/zhanglipeng6/ResNet/FPN/tools/../lib/fast_rcnn/train.py", line 146, in train_net model_paths = sw.train_model(max_iters) File "/home/zhanglipeng6/ResNet/FPN/tools/../lib/fast_rcnn/train.py", line 86, in train_model self.solver.step(1) File "/home/zhanglipeng6/ResNet/FPN/tools/../lib/rpn/proposal_target_layer.py", line 131, in forward rois_per_image, self._num_classes,sample_type='fpn', k0 = 4) File "/home/zhanglipeng6/ResNet/FPN/tools/../lib/rpn/proposal_target_layer.py", line 305, in _sample_rois _get_bbox_regression_labels(bbox_target_data, num_classes) File "/home/zhanglipeng6/ResNet/FPN/tools/../lib/rpn/proposal_target_layer.py", line 241, in _get_bbox_regression_labels bbox_targets[ind, start:end] = bbox_target_data[ind, 1:] TypeError: slice indices must be integers or None or have an index method

zh583007354 commented 5 years ago

The new problem is "ValueError: Could not broadcast input array from shape (4) into shape (0)" in this line.

guoqiang0148666 commented 4 years ago

@zh583007354

--- a/lib/rpn/proposal_target_layer.py
+++ b/lib/rpn/proposal_target_layer.py
@@ -124,7 +124,7 @@ class ProposalTargetLayer(caffe.Layer):

         num_images = 1
         rois_per_image = cfg.TRAIN.BATCH_SIZE / num_images
-        fg_rois_per_image = np.round(cfg.TRAIN.FG_FRACTION * rois_per_image)
+        fg_rois_per_image = np.round(cfg.TRAIN.FG_FRACTION * rois_per_image).astype(np.int)^M

         rois, labels, bbox_targets, bbox_weights ,layer_indexs = _sample_rois(
             all_rois, gt_boxes, fg_rois_per_image,
@@ -237,7 +237,9 @@ def _get_bbox_regression_labels(bbox_target_data, num_classes):
     for ind in inds:
         cls = clss[ind]
         start = 4 * cls
+        start = int(start)^M
         end = start + 4
+        end = int(end)^M
         bbox_targets[ind, start:end] = bbox_target_data[ind, 1:]
         bbox_inside_weights[ind, start:end] = cfg.TRAIN.BBOX_INSIDE_WEIGHTS
     return bbox_targets, bbox_inside_weights
@@ -275,6 +277,7 @@ def _sample_rois(all_rois, gt_boxes, fg_rois_per_image, rois_per_image, num_clas
     # Guard against the case when an image has fewer than fg_rois_per_image
     # foreground RoIs
     fg_rois_per_this_image = min(fg_rois_per_image, fg_inds.size)
+    fg_rois_per_this_image = int(fg_rois_per_this_image)^M
     # Sample foreground regions without replacement
     if fg_inds.size > 0:
         fg_inds = npr.choice(fg_inds, size=fg_rois_per_this_image, replace=False)
wangq0688 commented 3 years ago

Hello, I have some problems when running the codes on coco. Maybe you can solve it easily. Thank you very much. Traceback (most recent call last), File "./tools/train_net.py", line 112, in max_iters=args.max_iters) File "/home/zhanglipeng6/ResNet/FPN/tools/../lib/fast_rcnn/train.py", line 146, in train_net model_paths = sw.train_model(max_iters) File "/home/zhanglipeng6/ResNet/FPN/tools/../lib/fast_rcnn/train.py", line 86, in train_model self.solver.step(1) File "/home/zhanglipeng6/ResNet/FPN/tools/../lib/rpn/proposal_target_layer.py", line 131, in forward rois_per_image, self._num_classes,sample_type='fpn', k0 = 4) File "/home/zhanglipeng6/ResNet/FPN/tools/../lib/rpn/proposal_target_layer.py", line 305, in _sample_rois _get_bbox_regression_labels(bbox_target_data, num_classes) File "/home/zhanglipeng6/ResNet/FPN/tools/../lib/rpn/proposal_target_layer.py", line 241, in _get_bbox_regression_labels bbox_targets[ind, start:end] = bbox_target_data[ind, 1:] TypeError: slice indices must be integers or None or have an index method

Have you solved the problem??