diff --git a/mmcv/ops/deform_conv.py b/mmcv/ops/deform_conv.py index 2c31a6efb6..5c45bd4ebb 100644 --- a/mmcv/ops/deform_conv.py +++ b/mmcv/ops/deform_conv.py @@ -200,7 +200,7 @@ class DeformConv2d(nn.Module): channels to output channels. Default: 1. deform_groups (int): Number of deformable group partitions. bias (bool): If True, adds a learnable bias to the output. - Default: True. + Default: False. """ @@ -234,7 +234,6 @@ def __init__(self, self.dilation = _pair(dilation) self.groups = groups self.deform_groups = deform_groups - self.bias = bias # enable compatibility with nn.Conv2d self.transposed = False self.output_padding = _single(0) @@ -301,7 +300,8 @@ def __repr__(self): s += f'dilation={self.dilation},\n' s += f'groups={self.groups},\n' s += f'deform_groups={self.deform_groups},\n' - s += f'bias={self.bias})' + # bias is not supported in DeformConv2d. + s += 'deform_groups=False)' return s diff --git a/tests/test_ops/test_deform_conv.py b/tests/test_ops/test_deform_conv.py index 58b2e9f631..b99df8d011 100644 --- a/tests/test_ops/test_deform_conv.py +++ b/tests/test_ops/test_deform_conv.py @@ -1,4 +1,5 @@ import numpy as np +import pytest import torch input = [[[[1., 2., 3.], [0., 1., 2.], [3., 5., 2.]]]] @@ -56,6 +57,20 @@ def _test_deformconv(self, dtype=torch.float, threshold=1e-3): assert np.allclose(model.weight.grad.detach().cpu().numpy(), gt_deform_weight_grad, threshold) + from mmcv.ops import DeformConv2d + # test bias + model = DeformConv2d(1, 1, 2, stride=1, padding=0) + assert not hasattr(model, 'bias') + # test bias=True + with pytest.raises(AssertionError): + model = DeformConv2d(1, 1, 2, stride=1, padding=0, bias=True) + # test in_channels % group != 0 + with pytest.raises(AssertionError): + model = DeformConv2d(3, 2, 3, groups=2) + # test out_channels % group != 0 + with pytest.raises(AssertionError): + model = DeformConv2d(3, 4, 3, groups=3) + def test_deformconv(self): self._test_deformconv(torch.double) self._test_deformconv(torch.float)