internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: open-mmlab/mmdetection

Issue:
pad_val not used in class Pad when pad to a fixed size
in mmdet/datasets/pipelines/transforms.py **class Pad**
```python
    def _pad_img(self, results):
        if self.size is not None:
            padded_img = mmcv.impad(results['img'], self.size)
```
self.pad_val is not pass to mmcv.impad


Discussion:
Thanks for reporting the potential bug! You may create a PR to fix it if you would like to.

Resolving patch:
diff --git a/mmdet/datasets/pipelines/transforms.py b/mmdet/datasets/pipelines/transforms.py
--- a/mmdet/datasets/pipelines/transforms.py
+++ b/mmdet/datasets/pipelines/transforms.py
@@ -284,7 +284,7 @@ def __init__(self, size=None, size_divisor=None, pad_val=0):
 
     def _pad_img(self, results):
         if self.size is not None:
-            padded_img = mmcv.impad(results['img'], self.size)
+            padded_img = mmcv.impad(results['img'], self.size, self.pad_val)
         elif self.size_divisor is not None:
             padded_img = mmcv.impad_to_multiple(
                 results['img'], self.size_divisor, pad_val=self.pad_val)


Test patch:
Repository: open-mmlab/mmdetection

Issue:
AttributeError: Can't pickle local object 'build_dataloader.<locals>.worker_init_fn'
Recently, I update pytorch to 1.4. When running `tools/dist_train.sh submitted/faster_giou_train_config.py 1 --validate --autoscale-lr --seed 512`, one error raised: "AttributeError: Can't pickle local object 'build_dataloader.<locals>.worker_init_fn'". I found random seed caused this error, when running without `--seed`, it's ok.

I haven't ran script with `--seed` option in pytorch 1.3, so i don't know if it's the pytorch verion.

I wonder if this is a bug or a feature, Thank you in advance!


Discussion:
I have updated mmdet and mmcv to the latest.

Resolving patch:
diff --git a/mmdet/datasets/loader/build_loader.py b/mmdet/datasets/loader/build_loader.py
--- a/mmdet/datasets/loader/build_loader.py
+++ b/mmdet/datasets/loader/build_loader.py
@@ -61,12 +61,9 @@ def build_dataloader(dataset,
         batch_size = num_gpus * imgs_per_gpu
         num_workers = num_gpus * workers_per_gpu
 
-    def worker_init_fn(worker_id):
-        # The seed of each worker equals to
-        # num_worker * rank + worker_id + user_seed
-        worker_seed = num_workers * rank + worker_id + seed
-        np.random.seed(worker_seed)
-        random.seed(worker_seed)
+    init_fn = partial(
+        worker_init_fn, num_workers=num_workers, rank=rank,
+        seed=seed) if seed is not None else None
 
     data_loader = DataLoader(
         dataset,
@@ -75,7 +72,15 @@ def worker_init_fn(worker_id):
         num_workers=num_workers,
         collate_fn=partial(collate, samples_per_gpu=imgs_per_gpu),
         pin_memory=False,
-        worker_init_fn=worker_init_fn if seed is not None else None,
+        worker_init_fn=init_fn,
         **kwargs)
 
     return data_loader
+
+
+def worker_init_fn(worker_id, num_workers, rank, seed):
+    # The seed of each worker equals to
+    # num_worker * rank + worker_id + user_seed
+    worker_seed = num_workers * rank + worker_id + seed
+    np.random.seed(worker_seed)
+    random.seed(worker_seed)


Test patch:
Repository: open-mmlab/mmdetection

Issue:
ImportError: cannot import name 'CARAFENAIVE' from 'mmdet.ops.carafe'
The module name 'CARAFENAIVE' in file 'mmdet.ops.carafe.grad_check.py' shoud be 'CARAFENaive'. When I run this command 'python mmdet/ops/carafe/grad_check.py', the following error is reported: ImportError: cannot import name 'CARAFENAIVE' from 'mmdet.ops.carafe'.


Discussion:
Thanks! Would you like to create a PR to fix it?

Resolving patch:
diff --git a/mmdet/ops/carafe/grad_check.py b/mmdet/ops/carafe/grad_check.py
--- a/mmdet/ops/carafe/grad_check.py
+++ b/mmdet/ops/carafe/grad_check.py
@@ -6,9 +6,8 @@
 from torch.autograd import gradcheck
 
 sys.path.append(osp.abspath(osp.join(__file__, '../../')))
-from mmdet.ops.carafe import CARAFENAIVE  # noqa: E402, isort:skip
-from mmdet.ops.carafe import carafe_naive  # noqa: E402, isort:skip
-from mmdet.ops.carafe import carafe, CARAFE  # noqa: E402, isort:skip
+from mmdet.ops.carafe import CARAFE, CARAFENaive  # noqa: E402, isort:skip
+from mmdet.ops.carafe import carafe, carafe_naive  # noqa: E402, isort:skip
 
 feat = torch.randn(2, 64, 3, 3, requires_grad=True, device='cuda:0').double()
 mask = torch.randn(
@@ -19,7 +18,7 @@
 print(test)
 
 print('Gradcheck for carafe naive...')
-test = gradcheck(CARAFENAIVE(5, 4, 2), (feat, mask), atol=1e-4, eps=1e-4)
+test = gradcheck(CARAFENaive(5, 4, 2), (feat, mask), atol=1e-4, eps=1e-4)
 print(test)
 
 feat = torch.randn(


Test patch:
Repository: open-mmlab/mmdetection

Issue:
Memory leak?
Ever since using V2.0 I've noticed that my RAM memory keeps increasing every epoch. Which indicates that there is a memory leak somewhere.
Is someone else noticing the same behavior?



Discussion:

Resolving patch:
diff --git a/mmdet/core/evaluation/mean_ap.py b/mmdet/core/evaluation/mean_ap.py
--- a/mmdet/core/evaluation/mean_ap.py
+++ b/mmdet/core/evaluation/mean_ap.py
@@ -365,6 +365,7 @@ def eval_map(det_results,
             'precision': precisions,
             'ap': ap
         })
+    pool.close()
     if scale_ranges is not None:
         # shape (num_classes, num_scales)
         all_ap = np.vstack([cls_result['ap'] for cls_result in eval_results])


Test patch:
Repository: open-mmlab/mmdetection

Issue:
ModulatedDeformConv doesn't support different padding in H and W 
**Describe the bug**
ModulatedDeformConv doesn't support different padding in H and W. 
PS: My project only require (Modulated)DeformConv function so that it is directly imported.

**Error traceback**
```
File "src/models/deform_conv.py", line 421, in forward
    self.groups, self.deformable_groups)
  File "src/models/deform_conv.py", line 143, in forward
    ModulatedDeformConvFunction._infer_shape(ctx, input, weight))
  File "src/models/deform_conv.py", line 181, in _infer_shape
    height_out = (height + 2 * ctx.padding -
TypeError: unsupported operand type(s) for +: 'int' and 'tuple'
```

**Bug fix**
Unlike DeformConv, ModulatedDeformConv only supports the same padding in  height and width. It only accepts padding parameter as int not tuple which is inconsistent with what is said in the code comments 


Discussion:
Thanks for reporting the bug. It currently only supports padding the same h and w, and we will fix the docstring. PRs are welcome to add support for different paddings for each dim.

Resolving patch:
diff --git a/mmdet/ops/dcn/deform_conv.py b/mmdet/ops/dcn/deform_conv.py
--- a/mmdet/ops/dcn/deform_conv.py
+++ b/mmdet/ops/dcn/deform_conv.py
@@ -177,6 +177,7 @@ def _infer_shape(ctx, input, weight):
         channels_out = weight.size(0)
         height, width = input.shape[2:4]
         kernel_h, kernel_w = weight.shape[2:4]
+        # TODO: support different padding/stride/dilation in height and width
         height_out = (height + 2 * ctx.padding -
                       (ctx.dilation * (kernel_h - 1) + 1)) // ctx.stride + 1
         width_out = (width + 2 * ctx.padding -
@@ -389,9 +390,9 @@ class ModulatedDeformConvPack(ModulatedDeformConv):
         in_channels (int): Same as nn.Conv2d.
         out_channels (int): Same as nn.Conv2d.
         kernel_size (int or tuple[int]): Same as nn.Conv2d.
-        stride (int or tuple[int]): Same as nn.Conv2d.
-        padding (int or tuple[int]): Same as nn.Conv2d.
-        dilation (int or tuple[int]): Same as nn.Conv2d.
+        stride (int): Same as nn.Conv2d, while tuple is not supported.
+        padding (int): Same as nn.Conv2d, while tuple is not supported.
+        dilation (int): Same as nn.Conv2d, while tuple is not supported.
         groups (int): Same as nn.Conv2d.
         bias (bool or str): If specified as `auto`, it will be decided by the
             norm_cfg. Bias will be set as True if norm_cfg is None, otherwise


Test patch:
Repository: open-mmlab/mmdetection

Issue:
Can not train ATSS when samples_per_gpu=1.
https://github.com/open-mmlab/mmdetection/blob/8194b16d0bc2dcb99aeb21733d9c18cedb9e076a/mmdet/models/dense_heads/atss_head.py#L177

The mentioned code may produce non-contiguous tensor when batch=1.


Discussion:

Resolving patch:
diff --git a/mmdet/models/dense_heads/atss_head.py b/mmdet/models/dense_heads/atss_head.py
--- a/mmdet/models/dense_heads/atss_head.py
+++ b/mmdet/models/dense_heads/atss_head.py
@@ -173,8 +173,8 @@ def loss_single(self, anchors, cls_score, bbox_pred, centerness, labels,
         """
 
         anchors = anchors.reshape(-1, 4)
-        cls_score = cls_score.permute(0, 2, 3,
-                                      1).reshape(-1, self.cls_out_channels)
+        cls_score = cls_score.permute(0, 2, 3, 1).reshape(
+            -1, self.cls_out_channels).contiguous()
         bbox_pred = bbox_pred.permute(0, 2, 3, 1).reshape(-1, 4)
         centerness = centerness.permute(0, 2, 3, 1).reshape(-1)
         bbox_targets = bbox_targets.reshape(-1, 4)


Test patch:
Repository: open-mmlab/mmdetection

Issue:
`benchmark.py`.  ModuleNotFoundError: No module named 'tools.fuse_conv_bn'.
Recently the `tools/fuse_conv_bn.py`  was removed in #3529 . But the `benchmark.py`  is still trying to use the old script. 

[https://github.com/open-mmlab/mmdetection/blob/master/tools/benchmark.py#L8](https://github.com/open-mmlab/mmdetection/blob/master/tools/benchmark.py#L8)

I think this might be causing the error.

**Reproduction**
1. What command or script did you run?
```
tools/benchmark.py
```


Discussion:
`fuse_conv_bn` has been moved to mmcv.
@yhcao6 Please fix this bug.

Resolving patch:
diff --git a/tools/benchmark.py b/tools/benchmark.py
--- a/tools/benchmark.py
+++ b/tools/benchmark.py
@@ -3,9 +3,9 @@
 
 import torch
 from mmcv import Config
+from mmcv.cnn import fuse_conv_bn
 from mmcv.parallel import MMDataParallel
 from mmcv.runner import load_checkpoint
-from tools.fuse_conv_bn import fuse_module
 
 from mmdet.core import wrap_fp16_model
 from mmdet.datasets import build_dataloader, build_dataset
@@ -54,7 +54,7 @@ def main():
         wrap_fp16_model(model)
     load_checkpoint(model, args.checkpoint, map_location='cpu')
     if args.fuse_conv_bn:
-        model = fuse_module(model)
+        model = fuse_conv_bn(model)
 
     model = MMDataParallel(model, device_ids=[0])
 


Test patch:
Repository: open-mmlab/mmdetection

Issue:
Wrong class number for LVIS 1.0 dataset
**Checklist**
1. I have searched related issues but cannot get the expected help.
2. The bug has not been fixed in the latest version.

**Describe the bug**
Wrong class number for LVIS 1.0 dataset

**Reproduction**
1. What command or script did you run?
N.A.
2. Did you make any modifications on the code or config? Did you understand what you have modified?
Nope
3. What dataset did you use?
LVIS1.0

**Environment**
N.A.

**Error traceback**
N.A.

**Bug fix**
For the config file for LVIS1.0 dataset, the class number should be 1203 instead of 1230 as indicated on the official website:
https://www.lvisdataset.org/dataset

https://github.com/open-mmlab/mmdetection/blob/9596b9a4c916ae601f9a8a641c3a0ea47265abec/configs/lvis/mask_rcnn_r50_fpn_sample1e-3_mstrain_1x_lvis_v1.py#L8



Discussion:
It should be a typo, would you like to create a pr to fix that?

Resolving patch:
diff --git a/configs/lvis/mask_rcnn_r50_fpn_sample1e-3_mstrain_1x_lvis_v1.py b/configs/lvis/mask_rcnn_r50_fpn_sample1e-3_mstrain_1x_lvis_v1.py
--- a/configs/lvis/mask_rcnn_r50_fpn_sample1e-3_mstrain_1x_lvis_v1.py
+++ b/configs/lvis/mask_rcnn_r50_fpn_sample1e-3_mstrain_1x_lvis_v1.py
@@ -5,7 +5,7 @@
 ]
 model = dict(
     roi_head=dict(
-        bbox_head=dict(num_classes=1230), mask_head=dict(num_classes=1230)))
+        bbox_head=dict(num_classes=1203), mask_head=dict(num_classes=1203)))
 test_cfg = dict(
     rcnn=dict(
         score_thr=0.0001,


Test patch:
Repository: open-mmlab/mmdetection

Issue:
support for validate with batch size > 1
Hi, glad to know we could run the inference with batch size > 1, any plan to support validation during training with batch size > 1? According to 
https://github.com/open-mmlab/mmdetection/blob/c8511649550834ea168f610411a47a39cf194767/mmdet/apis/train.py#L113-L120
batch size is set to 1 for validation.


Discussion:
Hi @hubutui ,
Thanks for your suggestion. We may add this feature in the future.
@ZwwWayne Could you give me some sugesstions if I'd like to implement similar feature?

Resolving patch:
diff --git a/mmdet/apis/train.py b/mmdet/apis/train.py
--- a/mmdet/apis/train.py
+++ b/mmdet/apis/train.py
@@ -8,7 +8,8 @@
 from mmcv.utils import build_from_cfg
 
 from mmdet.core import DistEvalHook, EvalHook
-from mmdet.datasets import build_dataloader, build_dataset
+from mmdet.datasets import (build_dataloader, build_dataset,
+                            replace_ImageToTensor)
 from mmdet.utils import get_root_logger
 
 
@@ -111,10 +112,16 @@ def train_detector(model,
 
     # register eval hooks
     if validate:
+        # Support batch_size > 1 in validation
+        val_samples_per_gpu = cfg.data.val.pop('samples_per_gpu', 1)
+        if val_samples_per_gpu > 1:
+            # Replace 'ImageToTensor' to 'DefaultFormatBundle'
+            cfg.data.val.pipeline = replace_ImageToTensor(
+                cfg.data.val.pipeline)
         val_dataset = build_dataset(cfg.data.val, dict(test_mode=True))
         val_dataloader = build_dataloader(
             val_dataset,
-            samples_per_gpu=1,
+            samples_per_gpu=val_samples_per_gpu,
             workers_per_gpu=cfg.data.workers_per_gpu,
             dist=distributed,
             shuffle=False)


Test patch:
Repository: open-mmlab/mmdetection

Issue:
typo in WrapFieldsToLists docstring
https://github.com/open-mmlab/mmdetection/blob/fb287b144eee70134cd6369f70deb43fdb8d499a/mmdet/datasets/pipelines/formating.py#L327-L345

I think you mean `WrapFieldsToLists` instead of `WrapIntoLists` in line 343.


Discussion:
@hubutui, thanks for your comment, and I will fix the docstring.

Resolving patch:
diff --git a/mmdet/datasets/pipelines/formating.py b/mmdet/datasets/pipelines/formating.py
--- a/mmdet/datasets/pipelines/formating.py
+++ b/mmdet/datasets/pipelines/formating.py
@@ -340,7 +340,7 @@ class WrapFieldsToLists(object):
         >>>    dict(type='Pad', size_divisor=32),
         >>>    dict(type='ImageToTensor', keys=['img']),
         >>>    dict(type='Collect', keys=['img']),
-        >>>    dict(type='WrapIntoLists')
+        >>>    dict(type='WrapFieldsToLists')
         >>> ]
     """
 


Test patch:
Repository: open-mmlab/mmdetection

Issue:
batch_intput_shape
Typo in [batch_intput_shape](https://github.com/open-mmlab/mmdetection/blob/master/mmdet/models/dense_heads/transformer_head.py#L237) should probably be fixed here and in other places.


Discussion:
Hi @filaPro, could you give me a detailed suggestions or comments?
Hi @v-qjqs , I think `batch_intput_shape` should be renamed to `batch_input_shape`.
Hi @filaPro, thanks for your comments very much. Could you please create a PR to fix the type error?
Sure.

Resolving patch:
diff --git a/mmdet/models/dense_heads/transformer_head.py b/mmdet/models/dense_heads/transformer_head.py
--- a/mmdet/models/dense_heads/transformer_head.py
+++ b/mmdet/models/dense_heads/transformer_head.py
@@ -234,7 +234,7 @@ def forward_single(self, x, img_metas):
         # NOTE following the official DETR repo, non-zero values representing
         # ignored positions, while zero values means valid positions.
         batch_size = x.size(0)
-        input_img_h, input_img_w = img_metas[0]['batch_intput_shape']
+        input_img_h, input_img_w = img_metas[0]['batch_input_shape']
         masks = x.new_ones((batch_size, input_img_h, input_img_w))
         for img_id in range(batch_size):
             img_h, img_w, _ = img_metas[img_id]['img_shape']
diff --git a/mmdet/models/detectors/base.py b/mmdet/models/detectors/base.py
--- a/mmdet/models/detectors/base.py
+++ b/mmdet/models/detectors/base.py
@@ -76,9 +76,9 @@ def forward_train(self, imgs, img_metas, **kwargs):
         # NOTE the batched image size information may be useful, e.g.
         # in DETR, this is needed for the construction of masks, which is
         # then used for the transformer_head.
-        batch_intput_shape = tuple(imgs[0].size()[-2:])
+        batch_input_shape = tuple(imgs[0].size()[-2:])
         for img_meta in img_metas:
-            img_meta['batch_intput_shape'] = batch_intput_shape
+            img_meta['batch_input_shape'] = batch_input_shape
 
     async def async_simple_test(self, img, img_metas, **kwargs):
         raise NotImplementedError
@@ -146,7 +146,7 @@ def forward_test(self, imgs, img_metas, **kwargs):
         for img, img_meta in zip(imgs, img_metas):
             batch_size = len(img_meta)
             for img_id in range(batch_size):
-                img_meta[img_id]['batch_intput_shape'] = tuple(img.size()[-2:])
+                img_meta[img_id]['batch_input_shape'] = tuple(img.size()[-2:])
 
         if num_augs == 1:
             # proposals (List[List[Tensor]]): the outer list indicates


Test patch:
diff --git a/tests/test_models/test_heads.py b/tests/test_models/test_heads.py
--- a/tests/test_models/test_heads.py
+++ b/tests/test_models/test_heads.py
@@ -1238,7 +1238,7 @@ def test_transformer_head_loss():
         'img_shape': (s, s, 3),
         'scale_factor': 1,
         'pad_shape': (s, s, 3),
-        'batch_intput_shape': (s, s)
+        'batch_input_shape': (s, s)
     }]
     train_cfg = dict(
         assigner=dict(
Repository: open-mmlab/mmdetection

Issue:
Beta update assert error in dynamic rcnn
When the beta updates, new beta will be the median of the beta_history. It might be 0.0 but the beta used in loss function should be greater than 0.
The assert error occurred.
[https://github.com/open-mmlab/mmdetection/blob/5d07dda8719b0c67c11ad015410bc111e9f90200/mmdet/models/roi_heads/dynamic_roi_head.py#L144](url)
The code to fix it could be as follows:
`if np.abs(np.median(self.beta_history)) < 1e-15:
            new_beta = self.bbox_head.loss_bbox.beta
  else:
            new_beta = min(self.train_cfg.dynamic_rcnn.initial_beta,
                       np.median(self.beta_history))`
I am willing to create a PR to fix it as well.
Beta update assert error in dynamic rcnn
When the beta updates, new beta will be the median of the beta_history. It might be 0.0 but the beta used in loss function should be greater than 0.
The assert error occurred.
[https://github.com/open-mmlab/mmdetection/blob/5d07dda8719b0c67c11ad015410bc111e9f90200/mmdet/models/roi_heads/dynamic_roi_head.py#L144](url)
The code to fix it could be as follows:
`if np.abs(np.median(self.beta_history)) < 1e-15:
            new_beta = self.bbox_head.loss_bbox.beta
  else:
            new_beta = min(self.train_cfg.dynamic_rcnn.initial_beta,
                       np.median(self.beta_history))`
I am willing to create a PR to fix it as well.


Discussion:
Hi @formorebeat, you are welcome to create a PR to fix it.
Hi @formorebeat, you are welcome to create a PR to fix it.

Resolving patch:
diff --git a/mmdet/models/roi_heads/dynamic_roi_head.py b/mmdet/models/roi_heads/dynamic_roi_head.py
--- a/mmdet/models/roi_heads/dynamic_roi_head.py
+++ b/mmdet/models/roi_heads/dynamic_roi_head.py
@@ -6,6 +6,8 @@
 from ..builder import HEADS
 from .standard_roi_head import StandardRoIHead
 
+EPS = 1e-15
+
 
 @HEADS.register_module()
 class DynamicRoIHead(StandardRoIHead):
@@ -141,8 +143,12 @@ def update_hyperparameters(self):
         self.bbox_assigner.pos_iou_thr = new_iou_thr
         self.bbox_assigner.neg_iou_thr = new_iou_thr
         self.bbox_assigner.min_pos_iou = new_iou_thr
-        new_beta = min(self.train_cfg.dynamic_rcnn.initial_beta,
-                       np.median(self.beta_history))
+        if (np.median(self.beta_history) < EPS):
+            # avoid 0 or too small value for new_beta
+            new_beta = self.bbox_head.loss_bbox.beta
+        else:
+            new_beta = min(self.train_cfg.dynamic_rcnn.initial_beta,
+                           np.median(self.beta_history))
         self.beta_history = []
         self.bbox_head.loss_bbox.beta = new_beta
         return new_iou_thr, new_beta


Test patch:
Repository: open-mmlab/mmdetection

Issue:
Invalid link in readme of cityscape
Hi, Thank you very much for the amazing project! 

I would like to report that the [model](http://download.openmmlab.com/mmdetection/v2.0/cityscapes/mask_rcnn_r50_fpn_1x_cityscapes_20200502-6ea77f0e.pth) in the [readme](https://github.com/open-mmlab/mmdetection/blob/master/configs/cityscapes/README.md) in the cityscape is invalid. 

Meanwhile, may I ask whether there are more pre-trained models on Cityscape? I would like to evaluate the models elaborately. 

Thank you!


Discussion:
Hi @luzai, thanks for your comments, and we will train the model and provide the checkpoints soon.

Resolving patch:
diff --git a/mmdet/core/bbox/assigners/hungarian_assigner.py b/mmdet/core/bbox/assigners/hungarian_assigner.py
--- a/mmdet/core/bbox/assigners/hungarian_assigner.py
+++ b/mmdet/core/bbox/assigners/hungarian_assigner.py
@@ -1,5 +1,9 @@
 import torch
-from scipy.optimize import linear_sum_assignment
+
+try:
+    from scipy.optimize import linear_sum_assignment
+except ImportError:
+    linear_sum_assignment = None
 
 from ..builder import BBOX_ASSIGNERS
 from ..iou_calculators import build_iou_calculator
@@ -142,6 +146,9 @@ def assign(self,
 
         # 3. do Hungarian matching on CPU using linear_sum_assignment
         cost = cost.detach().cpu()
+        if linear_sum_assignment is None:
+            raise ImportError('Please run "pip install scipy" '
+                              'to install scipy first.')
         matched_row_inds, matched_col_inds = linear_sum_assignment(cost)
         matched_row_inds = torch.from_numpy(matched_row_inds).to(
             bbox_pred.device)


Test patch: