Repository: open-mmlab/mmdetection

Issue:
MultiScaleFlipAug test seems wrong, TypeError: list indices must be integers or slices, not str
 File "tools/test.py", line 162, in <module>
    main()
  File "tools/test.py", line 140, in main
    outputs = single_gpu_test(model, data_loader, args.show)
  File "/content/mmdetection/mmdet/apis/test.py", line 19, in single_gpu_test
    result = model(return_loss=False, rescale=not show, **data)
  File "/content/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "/content/anaconda3/lib/python3.7/site-packages/torch/nn/parallel/data_parallel.py", line 150, in forward
    return self.module(*inputs[0], **kwargs[0])
  File "/content/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "/content/mmdetection/mmdet/core/fp16/decorators.py", line 49, in new_func
    return old_func(*args, **kwargs)
  File "/content/mmdetection/mmdet/models/detectors/base.py", line 149, in forward
    return self.forward_test(img, img_metas, **kwargs)
  File "/content/mmdetection/mmdet/models/detectors/base.py", line 134, in forward_test
    return self.aug_test(imgs, img_metas, **kwargs)
  File "/content/mmdetection/mmdet/models/detectors/two_stage.py", line 327, in aug_test
    self.extract_feats(imgs), img_metas, self.test_cfg.rpn)
  File "/content/mmdetection/mmdet/models/detectors/test_mixins.py", line 41, in aug_test_rpn
    proposal_list = self.simple_test_rpn(x, img_metas, rpn_test_cfg)
  File "/content/mmdetection/mmdet/models/detectors/test_mixins.py", line 34, in simple_test_rpn
    proposal_list = self.rpn_head.get_bboxes(*proposal_inputs)
  File "/content/mmdetection/mmdet/core/fp16/decorators.py", line 127, in new_func
    return old_func(*args, **kwargs)
  File "/content/mmdetection/mmdet/models/anchor_heads/anchor_head.py", line 274, in get_bboxes
    img_shape = img_metas[img_id]['img_shape']
TypeError: list indices must be integers or slices, not str

ps: Single test is right, but it's wrong when use Mutli-Test , I guess this bug that is due to update before 5 hours


Discussion:
Please follow the `Error report` issue template.
> Please follow the `Error report` issue template.

I have tested  original code(configs: cascade_rcnn_r50_fpn_1x.py), MultiScaleFlipAug test didn't work, for example, 
test_pipeline = [
    dict(type='LoadImageFromFile'),
    dict(
        type='MultiScaleFlipAug',
        img_scale=[(1333, 800), (2666, 1600)],
        flip=False,
        transforms=[
            dict(type='Resize', keep_ratio=True),
            dict(type='RandomFlip'),
            dict(type='Normalize', **img_norm_cfg),
            dict(type='Pad', size_divisor=32),
            dict(type='ImageToTensor', keys=['img']),
            dict(type='Collect', keys=['img']),
        ])
],
before upgrade this code, it worked ver well.
thank you very much, this code( yhcao6) works well.
i have this problem too ,can you tell me how to solve it
how to solve the problem
> thank you very much, this code( yhcao6) works well.


how to solve the problem
> i have this problem too ,can you tell me how to solve it

Did you solve the problem?I met the same
> > i have this problem too ,can you tell me how to solve it
> 
> Did you solve the problem?I met the same

copy mmdet code( yhcao6) to your project.


> > > i have this problem too ,can you tell me how to solve it
> > 
> > 
> > Did you solve the problem?I met the same
> 
> copy mmdet code( yhcao6) to your project.

老哥，code(yhcao6)是指https://github.com/yhcao6/mmdetection这个库的代码吗？我复制了一下这个库里的mmdet，还是遇到了同样的问题😔
Does code (yhcao6) mean the link https://github.com/yhcao6/mmdetection ? I copied the mmdet from this repository, and I still met the same problem.
I copy the code，but it did not work，any advice?
> > > > i have this problem too ,can you tell me how to solve it
> > > 
> > > 
> > > Did you solve the problem?I met the same
> > 
> > 
> > copy mmdet code( yhcao6) to your project.
> 
> 老哥，code(yhcao6)是指[https://github.com/yhcao6/mmdetection这个库的代码吗？我复制了一下这个库里的mmdet，还是遇到了同样的问题😔](https://github.com/yhcao6/mmdetection%E8%BF%99%E4%B8%AA%E5%BA%93%E7%9A%84%E4%BB%A3%E7%A0%81%E5%90%97%EF%BC%9F%E6%88%91%E5%A4%8D%E5%88%B6%E4%BA%86%E4%B8%80%E4%B8%8B%E8%BF%99%E4%B8%AA%E5%BA%93%E9%87%8C%E7%9A%84mmdet%EF%BC%8C%E8%BF%98%E6%98%AF%E9%81%87%E5%88%B0%E4%BA%86%E5%90%8C%E6%A0%B7%E7%9A%84%E9%97%AE%E9%A2%98%F0%9F%98%94)
> Does code (yhcao6) mean the link https://github.com/yhcao6/mmdetection ? I copied the mmdet from this repository, and I still met the same problem.

do u run pip install -v -e .or "python setup.py develop"after copy？
> I copy the code，but it did not work，any advice?

do u run pip install -v -e .or "python setup.py develop"after copy？
> > I copy the code，but it did not work，any advice?
> 
> do u run pip install -v -e .or "python setup.py develop"after copy？

yes, i rebuild the project, but still doesn't work
But I used an earlier version and solved the problem

> > > I copy the code，but it did not work，any advice?
> > 
> > 
> > do u run pip install -v -e .or "python setup.py develop"after copy？
> 
> yes, i rebuild the project, but still doesn't work

But I use an earlier version and solved the problem

Resolving patch:
diff --git a/mmdet/models/detectors/cascade_rcnn.py b/mmdet/models/detectors/cascade_rcnn.py
--- a/mmdet/models/detectors/cascade_rcnn.py
+++ b/mmdet/models/detectors/cascade_rcnn.py
@@ -419,9 +419,9 @@ def aug_test(self, imgs, img_metas, proposals=None, rescale=False):
         aug_scores = []
         for x, img_meta in zip(self.extract_feats(imgs), img_metas):
             # only one image in the batch
-            img_shape = img_metas[0]['img_shape']
-            scale_factor = img_metas[0]['scale_factor']
-            flip = img_metas[0]['flip']
+            img_shape = img_meta[0]['img_shape']
+            scale_factor = img_meta[0]['scale_factor']
+            flip = img_meta[0]['flip']
 
             proposals = bbox_mapping(proposal_list[0][:, :4], img_shape,
                                      scale_factor, flip)
@@ -444,7 +444,7 @@ def aug_test(self, imgs, img_metas, proposals=None, rescale=False):
                 if i < self.num_stages - 1:
                     bbox_label = cls_score.argmax(dim=1)
                     rois = bbox_head.regress_by_class(rois, bbox_label,
-                                                      bbox_pred, img_metas[0])
+                                                      bbox_pred, img_meta[0])
 
             cls_score = sum(ms_scores) / float(len(ms_scores))
             bboxes, scores = self.bbox_head[-1].get_det_bboxes(
@@ -478,9 +478,9 @@ def aug_test(self, imgs, img_metas, proposals=None, rescale=False):
                 aug_masks = []
                 aug_img_metas = []
                 for x, img_meta in zip(self.extract_feats(imgs), img_metas):
-                    img_shape = img_metas[0]['img_shape']
-                    scale_factor = img_metas[0]['scale_factor']
-                    flip = img_metas[0]['flip']
+                    img_shape = img_meta[0]['img_shape']
+                    scale_factor = img_meta[0]['scale_factor']
+                    flip = img_meta[0]['flip']
                     _bboxes = bbox_mapping(det_bboxes[:, :4], img_shape,
                                            scale_factor, flip)
                     mask_rois = bbox2roi([_bboxes])


Test patch:
diff --git a/mmdet/models/detectors/test_mixins.py b/mmdet/models/detectors/test_mixins.py
--- a/mmdet/models/detectors/test_mixins.py
+++ b/mmdet/models/detectors/test_mixins.py
@@ -38,7 +38,7 @@ def aug_test_rpn(self, feats, img_metas, rpn_test_cfg):
         imgs_per_gpu = len(img_metas[0])
         aug_proposals = [[] for _ in range(imgs_per_gpu)]
         for x, img_meta in zip(feats, img_metas):
-            proposal_list = self.simple_test_rpn(x, img_metas, rpn_test_cfg)
+            proposal_list = self.simple_test_rpn(x, img_meta, rpn_test_cfg)
             for i, proposals in enumerate(proposal_list):
                 aug_proposals[i].append(proposals)
         # reorganize the order of 'img_metas' to match the dimensions
@@ -124,9 +124,9 @@ def aug_test_bboxes(self, feats, img_metas, proposal_list, rcnn_test_cfg):
         aug_scores = []
         for x, img_meta in zip(feats, img_metas):
             # only one image in the batch
-            img_shape = img_metas[0]['img_shape']
-            scale_factor = img_metas[0]['scale_factor']
-            flip = img_metas[0]['flip']
+            img_shape = img_meta[0]['img_shape']
+            scale_factor = img_meta[0]['scale_factor']
+            flip = img_meta[0]['flip']
             # TODO more flexible
             proposals = bbox_mapping(proposal_list[0][:, :4], img_shape,
                                      scale_factor, flip)
@@ -237,9 +237,9 @@ def aug_test_mask(self, feats, img_metas, det_bboxes, det_labels):
         else:
             aug_masks = []
             for x, img_meta in zip(feats, img_metas):
-                img_shape = img_metas[0]['img_shape']
-                scale_factor = img_metas[0]['scale_factor']
-                flip = img_metas[0]['flip']
+                img_shape = img_meta[0]['img_shape']
+                scale_factor = img_meta[0]['scale_factor']
+                flip = img_meta[0]['flip']
                 _bboxes = bbox_mapping(det_bboxes[:, :4], img_shape,
                                        scale_factor, flip)
                 mask_rois = bbox2roi([_bboxes])