We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[feature request] add 3D support to build_upsample_layer
Currently, `mmcv.cnn.build_upsample_layer` support type `nearest, bilinear, deconv, pixel_shuffle`. It means ` ConvTranspose2d` by deconv. It would be great if we also support `ConvTranspose3d`.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `mmcv/cnn/bricks/depthwise_separable_conv_module.py`
Content:
```
1 import torch.nn as nn
2 
3 from .conv_module import ConvModule
4 
5 
6 class DepthwiseSeparableConvModule(nn.Module):
7     """Depthwise separable convolution module.
8 
9     See https://arxiv.org/pdf/1704.04861.pdf for details.
10 
11     This module can replace a ConvModule with the conv block replaced by two
12     conv block: depthwise conv block and pointwise conv block. The depthwise
13     conv block contains depthwise-conv/norm/activation layers. The pointwise
14     conv block contains pointwise-conv/norm/activation layers. It should be
15     noted that there will be norm/activation layer in the depthwise conv block
16     if `norm_cfg` and `act_cfg` are specified.
17 
18     Args:
19         in_channels (int): Same as nn.Conv2d.
20         out_channels (int): Same as nn.Conv2d.
21         kernel_size (int or tuple[int]): Same as nn.Conv2d.
22         stride (int or tuple[int]): Same as nn.Conv2d. Default: 1.
23         padding (int or tuple[int]): Same as nn.Conv2d. Default: 0.
24         dilation (int or tuple[int]): Same as nn.Conv2d. Default: 1.
25         norm_cfg (dict): Default norm config for both depthwise ConvModule and
26             pointwise ConvModule. Default: None.
27         act_cfg (dict): Default activation config for both depthwise ConvModule
28             and pointwise ConvModule. Default: dict(type='ReLU').
29         dw_norm_cfg (dict): Norm config of depthwise ConvModule. If it is
30             'default', it will be the same as `norm_cfg`. Default: 'default'.
31         dw_act_cfg (dict): Activation config of depthwise ConvModule. If it is
32             'default', it will be the same as `act_cfg`. Default: 'default'.
33         pw_norm_cfg (dict): Norm config of pointwise ConvModule. If it is
34             'default', it will be the same as `norm_cfg`. Default: 'default'.
35         pw_act_cfg (dict): Activation config of pointwise ConvModule. If it is
36             'default', it will be the same as `act_cfg`. Default: 'default'.
37         kwargs (optional): Other shared arguments for depthwise and pointwise
38             ConvModule. See ConvModule for ref.
39     """
40 
41     def __init__(self,
42                  in_channels,
43                  out_channels,
44                  kernel_size,
45                  stride=1,
46                  padding=0,
47                  dilation=1,
48                  norm_cfg=None,
49                  act_cfg=dict(type='ReLU'),
50                  dw_norm_cfg='default',
51                  dw_act_cfg='default',
52                  pw_norm_cfg='default',
53                  pw_act_cfg='default',
54                  **kwargs):
55         super(DepthwiseSeparableConvModule, self).__init__()
56         assert 'groups' not in kwargs, 'groups should not be specified'
57 
58         # if norm/activation config of depthwise/pointwise ConvModule is not
59         # specified, use default config.
60         dw_norm_cfg = dw_norm_cfg if dw_norm_cfg != 'default' else norm_cfg
61         dw_act_cfg = dw_act_cfg if dw_act_cfg != 'default' else act_cfg
62         pw_norm_cfg = pw_norm_cfg if pw_norm_cfg != 'default' else norm_cfg
63         pw_act_cfg = pw_act_cfg if pw_act_cfg != 'default' else act_cfg
64 
65         # depthwise convolution
66         self.depthwise_conv = ConvModule(
67             in_channels,
68             in_channels,
69             kernel_size,
70             stride=stride,
71             padding=padding,
72             dilation=dilation,
73             groups=in_channels,
74             norm_cfg=dw_norm_cfg,
75             act_cfg=dw_act_cfg,
76             **kwargs)
77 
78         self.pointwise_conv = ConvModule(
79             in_channels,
80             out_channels,
81             1,
82             norm_cfg=pw_norm_cfg,
83             act_cfg=pw_act_cfg,
84             **kwargs)
85 
86     def forward(self, x):
87         x = self.depthwise_conv(x)
88         x = self.pointwise_conv(x)
89         return x
90
```

Path: `mmcv/cnn/bricks/conv_module.py`
Content:
```
1 import warnings
2 
3 import torch.nn as nn
4 
5 from ..utils import constant_init, kaiming_init
6 from .activation import build_activation_layer
7 from .conv import build_conv_layer
8 from .norm import build_norm_layer
9 from .padding import build_padding_layer
10 from .registry import PLUGIN_LAYERS
11 
12 
13 @PLUGIN_LAYERS.register_module()
14 class ConvModule(nn.Module):
15     """A conv block that bundles conv/norm/activation layers.
16 
17     This block simplifies the usage of convolution layers, which are commonly
18     used with a norm layer (e.g., BatchNorm) and activation layer (e.g., ReLU).
19     It is based upon three build methods: `build_conv_layer()`,
20     `build_norm_layer()` and `build_activation_layer()`.
21 
22     Besides, we add some additional features in this module.
23     1. Automatically set `bias` of the conv layer.
24     2. Spectral norm is supported.
25     3. More padding modes are supported. Before PyTorch 1.5, nn.Conv2d only
26     supports zero and circular padding, and we add "reflect" padding mode.
27 
28     Args:
29         in_channels (int): Same as nn.Conv2d.
30         out_channels (int): Same as nn.Conv2d.
31         kernel_size (int | tuple[int]): Same as nn.Conv2d.
32         stride (int | tuple[int]): Same as nn.Conv2d.
33         padding (int | tuple[int]): Same as nn.Conv2d.
34         dilation (int | tuple[int]): Same as nn.Conv2d.
35         groups (int): Same as nn.Conv2d.
36         bias (bool | str): If specified as `auto`, it will be decided by the
37             norm_cfg. Bias will be set as True if `norm_cfg` is None, otherwise
38             False. Default: "auto".
39         conv_cfg (dict): Config dict for convolution layer. Default: None,
40             which means using conv2d.
41         norm_cfg (dict): Config dict for normalization layer. Default: None.
42         act_cfg (dict): Config dict for activation layer.
43             Default: dict(type='ReLU').
44         inplace (bool): Whether to use inplace mode for activation.
45             Default: True.
46         with_spectral_norm (bool): Whether use spectral norm in conv module.
47             Default: False.
48         padding_mode (str): If the `padding_mode` has not been supported by
49             current `Conv2d` in PyTorch, we will use our own padding layer
50             instead. Currently, we support ['zeros', 'circular'] with official
51             implementation and ['reflect'] with our own implementation.
52             Default: 'zeros'.
53         order (tuple[str]): The order of conv/norm/activation layers. It is a
54             sequence of "conv", "norm" and "act". Common examples are
55             ("conv", "norm", "act") and ("act", "conv", "norm").
56             Default: ('conv', 'norm', 'act').
57     """
58 
59     _abbr_ = 'conv_block'
60 
61     def __init__(self,
62                  in_channels,
63                  out_channels,
64                  kernel_size,
65                  stride=1,
66                  padding=0,
67                  dilation=1,
68                  groups=1,
69                  bias='auto',
70                  conv_cfg=None,
71                  norm_cfg=None,
72                  act_cfg=dict(type='ReLU'),
73                  inplace=True,
74                  with_spectral_norm=False,
75                  padding_mode='zeros',
76                  order=('conv', 'norm', 'act')):
77         super(ConvModule, self).__init__()
78         assert conv_cfg is None or isinstance(conv_cfg, dict)
79         assert norm_cfg is None or isinstance(norm_cfg, dict)
80         assert act_cfg is None or isinstance(act_cfg, dict)
81         official_padding_mode = ['zeros', 'circular']
82         self.conv_cfg = conv_cfg
83         self.norm_cfg = norm_cfg
84         self.act_cfg = act_cfg
85         self.inplace = inplace
86         self.with_spectral_norm = with_spectral_norm
87         self.with_explicit_padding = padding_mode not in official_padding_mode
88         self.order = order
89         assert isinstance(self.order, tuple) and len(self.order) == 3
90         assert set(order) == set(['conv', 'norm', 'act'])
91 
92         self.with_norm = norm_cfg is not None
93         self.with_activation = act_cfg is not None
94         # if the conv layer is before a norm layer, bias is unnecessary.
95         if bias == 'auto':
96             bias = not self.with_norm
97         self.with_bias = bias
98 
99         if self.with_norm and self.with_bias:
100             warnings.warn('ConvModule has norm and bias at the same time')
101 
102         if self.with_explicit_padding:
103             pad_cfg = dict(type=padding_mode)
104             self.padding_layer = build_padding_layer(pad_cfg, padding)
105 
106         # reset padding to 0 for conv module
107         conv_padding = 0 if self.with_explicit_padding else padding
108         # build convolution layer
109         self.conv = build_conv_layer(
110             conv_cfg,
111             in_channels,
112             out_channels,
113             kernel_size,
114             stride=stride,
115             padding=conv_padding,
116             dilation=dilation,
117             groups=groups,
118             bias=bias)
119         # export the attributes of self.conv to a higher level for convenience
120         self.in_channels = self.conv.in_channels
121         self.out_channels = self.conv.out_channels
122         self.kernel_size = self.conv.kernel_size
123         self.stride = self.conv.stride
124         self.padding = padding
125         self.dilation = self.conv.dilation
126         self.transposed = self.conv.transposed
127         self.output_padding = self.conv.output_padding
128         self.groups = self.conv.groups
129 
130         if self.with_spectral_norm:
131             self.conv = nn.utils.spectral_norm(self.conv)
132 
133         # build normalization layers
134         if self.with_norm:
135             # norm layer is after conv layer
136             if order.index('norm') > order.index('conv'):
137                 norm_channels = out_channels
138             else:
139                 norm_channels = in_channels
140             self.norm_name, norm = build_norm_layer(norm_cfg, norm_channels)
141             self.add_module(self.norm_name, norm)
142 
143         # build activation layer
144         if self.with_activation:
145             act_cfg_ = act_cfg.copy()
146             # nn.Tanh has no 'inplace' argument
147             if act_cfg_['type'] not in [
148                     'Tanh', 'PReLU', 'Sigmoid', 'HSigmoid', 'Swish'
149             ]:
150                 act_cfg_.setdefault('inplace', inplace)
151             self.activate = build_activation_layer(act_cfg_)
152 
153         # Use msra init by default
154         self.init_weights()
155 
156     @property
157     def norm(self):
158         return getattr(self, self.norm_name)
159 
160     def init_weights(self):
161         # 1. It is mainly for customized conv layers with their own
162         #    initialization manners, and we do not want ConvModule to
163         #    overrides the initialization.
164         # 2. For customized conv layers without their own initialization
165         #    manners, they will be initialized by this method with default
166         #    `kaiming_init`.
167         # 3. For PyTorch's conv layers, they will be initialized anyway by
168         #    their own `reset_parameters` methods.
169         if not hasattr(self.conv, 'init_weights'):
170             if self.with_activation and self.act_cfg['type'] == 'LeakyReLU':
171                 nonlinearity = 'leaky_relu'
172                 a = self.act_cfg.get('negative_slope', 0.01)
173             else:
174                 nonlinearity = 'relu'
175                 a = 0
176             kaiming_init(self.conv, a=a, nonlinearity=nonlinearity)
177         if self.with_norm:
178             constant_init(self.norm, 1, bias=0)
179 
180     def forward(self, x, activate=True, norm=True):
181         for layer in self.order:
182             if layer == 'conv':
183                 if self.with_explicit_padding:
184                     x = self.padding_layer(x)
185                 x = self.conv(x)
186             elif layer == 'norm' and norm and self.with_norm:
187                 x = self.norm(x)
188             elif layer == 'act' and activate and self.with_activation:
189                 x = self.activate(x)
190         return x
191
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/mmcv/cnn/bricks/conv_module.py b/mmcv/cnn/bricks/conv_module.py
--- a/mmcv/cnn/bricks/conv_module.py
+++ b/mmcv/cnn/bricks/conv_module.py
@@ -26,13 +26,20 @@
     supports zero and circular padding, and we add "reflect" padding mode.
 
     Args:
-        in_channels (int): Same as nn.Conv2d.
-        out_channels (int): Same as nn.Conv2d.
-        kernel_size (int | tuple[int]): Same as nn.Conv2d.
-        stride (int | tuple[int]): Same as nn.Conv2d.
-        padding (int | tuple[int]): Same as nn.Conv2d.
-        dilation (int | tuple[int]): Same as nn.Conv2d.
-        groups (int): Same as nn.Conv2d.
+        in_channels (int): Number of channels in the input feature map.
+            Same as that in ``nn._ConvNd``.
+        out_channels (int): Number of channels produced by the convolution.
+            Same as that in ``nn._ConvNd``.
+        kernel_size (int | tuple[int]): Size of the convolving kernel.
+            Same as that in ``nn._ConvNd``.
+        stride (int | tuple[int]): Stride of the convolution.
+            Same as that in ``nn._ConvNd``.
+        padding (int | tuple[int]): Zero-padding added to both sides of
+            the input. Same as that in ``nn._ConvNd``.
+        dilation (int | tuple[int]): Spacing between kernel elements.
+            Same as that in ``nn._ConvNd``.
+        groups (int): Number of blocked connections from input channels to
+            output channels. Same as that in ``nn._ConvNd``.
         bias (bool | 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
             False. Default: "auto".
diff --git a/mmcv/cnn/bricks/depthwise_separable_conv_module.py b/mmcv/cnn/bricks/depthwise_separable_conv_module.py
--- a/mmcv/cnn/bricks/depthwise_separable_conv_module.py
+++ b/mmcv/cnn/bricks/depthwise_separable_conv_module.py
@@ -16,12 +16,18 @@
     if `norm_cfg` and `act_cfg` are specified.
 
     Args:
-        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. Default: 1.
-        padding (int or tuple[int]): Same as nn.Conv2d. Default: 0.
-        dilation (int or tuple[int]): Same as nn.Conv2d. Default: 1.
+        in_channels (int): Number of channels in the input feature map.
+            Same as that in ``nn._ConvNd``.
+        out_channels (int): Number of channels produced by the convolution.
+            Same as that in ``nn._ConvNd``.
+        kernel_size (int | tuple[int]): Size of the convolving kernel.
+            Same as that in ``nn._ConvNd``.
+        stride (int | tuple[int]): Stride of the convolution.
+            Same as that in ``nn._ConvNd``. Default: 1.
+        padding (int | tuple[int]): Zero-padding added to both sides of
+            the input. Same as that in ``nn._ConvNd``. Default: 0.
+        dilation (int | tuple[int]): Spacing between kernel elements.
+            Same as that in ``nn._ConvNd``. Default: 1.
         norm_cfg (dict): Default norm config for both depthwise ConvModule and
             pointwise ConvModule. Default: None.
         act_cfg (dict): Default activation config for both depthwise ConvModule

{"golden_diff": "diff --git a/mmcv/cnn/bricks/conv_module.py b/mmcv/cnn/bricks/conv_module.py\n--- a/mmcv/cnn/bricks/conv_module.py\n+++ b/mmcv/cnn/bricks/conv_module.py\n@@ -26,13 +26,20 @@\n     supports zero and circular padding, and we add \"reflect\" padding mode.\n \n     Args:\n-        in_channels (int): Same as nn.Conv2d.\n-        out_channels (int): Same as nn.Conv2d.\n-        kernel_size (int | tuple[int]): Same as nn.Conv2d.\n-        stride (int | tuple[int]): Same as nn.Conv2d.\n-        padding (int | tuple[int]): Same as nn.Conv2d.\n-        dilation (int | tuple[int]): Same as nn.Conv2d.\n-        groups (int): Same as nn.Conv2d.\n+        in_channels (int): Number of channels in the input feature map.\n+            Same as that in ``nn._ConvNd``.\n+        out_channels (int): Number of channels produced by the convolution.\n+            Same as that in ``nn._ConvNd``.\n+        kernel_size (int | tuple[int]): Size of the convolving kernel.\n+            Same as that in ``nn._ConvNd``.\n+        stride (int | tuple[int]): Stride of the convolution.\n+            Same as that in ``nn._ConvNd``.\n+        padding (int | tuple[int]): Zero-padding added to both sides of\n+            the input. Same as that in ``nn._ConvNd``.\n+        dilation (int | tuple[int]): Spacing between kernel elements.\n+            Same as that in ``nn._ConvNd``.\n+        groups (int): Number of blocked connections from input channels to\n+            output channels. Same as that in ``nn._ConvNd``.\n         bias (bool | str): If specified as `auto`, it will be decided by the\n             norm_cfg. Bias will be set as True if `norm_cfg` is None, otherwise\n             False. Default: \"auto\".\ndiff --git a/mmcv/cnn/bricks/depthwise_separable_conv_module.py b/mmcv/cnn/bricks/depthwise_separable_conv_module.py\n--- a/mmcv/cnn/bricks/depthwise_separable_conv_module.py\n+++ b/mmcv/cnn/bricks/depthwise_separable_conv_module.py\n@@ -16,12 +16,18 @@\n     if `norm_cfg` and `act_cfg` are specified.\n \n     Args:\n-        in_channels (int): Same as nn.Conv2d.\n-        out_channels (int): Same as nn.Conv2d.\n-        kernel_size (int or tuple[int]): Same as nn.Conv2d.\n-        stride (int or tuple[int]): Same as nn.Conv2d. Default: 1.\n-        padding (int or tuple[int]): Same as nn.Conv2d. Default: 0.\n-        dilation (int or tuple[int]): Same as nn.Conv2d. Default: 1.\n+        in_channels (int): Number of channels in the input feature map.\n+            Same as that in ``nn._ConvNd``.\n+        out_channels (int): Number of channels produced by the convolution.\n+            Same as that in ``nn._ConvNd``.\n+        kernel_size (int | tuple[int]): Size of the convolving kernel.\n+            Same as that in ``nn._ConvNd``.\n+        stride (int | tuple[int]): Stride of the convolution.\n+            Same as that in ``nn._ConvNd``. Default: 1.\n+        padding (int | tuple[int]): Zero-padding added to both sides of\n+            the input. Same as that in ``nn._ConvNd``. Default: 0.\n+        dilation (int | tuple[int]): Spacing between kernel elements.\n+            Same as that in ``nn._ConvNd``. Default: 1.\n         norm_cfg (dict): Default norm config for both depthwise ConvModule and\n             pointwise ConvModule. Default: None.\n         act_cfg (dict): Default activation config for both depthwise ConvModule\n", "issue": "[feature request] add 3D support to build_upsample_layer\nCurrently, `mmcv.cnn.build_upsample_layer` support type `nearest, bilinear, deconv, pixel_shuffle`. It means ` ConvTranspose2d` by deconv. It would be great if we also support `ConvTranspose3d`.\n", "before_files": [{"content": "import torch.nn as nn\n\nfrom .conv_module import ConvModule\n\n\nclass DepthwiseSeparableConvModule(nn.Module):\n    \"\"\"Depthwise separable convolution module.\n\n    See https://arxiv.org/pdf/1704.04861.pdf for details.\n\n    This module can replace a ConvModule with the conv block replaced by two\n    conv block: depthwise conv block and pointwise conv block. The depthwise\n    conv block contains depthwise-conv/norm/activation layers. The pointwise\n    conv block contains pointwise-conv/norm/activation layers. It should be\n    noted that there will be norm/activation layer in the depthwise conv block\n    if `norm_cfg` and `act_cfg` are specified.\n\n    Args:\n        in_channels (int): Same as nn.Conv2d.\n        out_channels (int): Same as nn.Conv2d.\n        kernel_size (int or tuple[int]): Same as nn.Conv2d.\n        stride (int or tuple[int]): Same as nn.Conv2d. Default: 1.\n        padding (int or tuple[int]): Same as nn.Conv2d. Default: 0.\n        dilation (int or tuple[int]): Same as nn.Conv2d. Default: 1.\n        norm_cfg (dict): Default norm config for both depthwise ConvModule and\n            pointwise ConvModule. Default: None.\n        act_cfg (dict): Default activation config for both depthwise ConvModule\n            and pointwise ConvModule. Default: dict(type='ReLU').\n        dw_norm_cfg (dict): Norm config of depthwise ConvModule. If it is\n            'default', it will be the same as `norm_cfg`. Default: 'default'.\n        dw_act_cfg (dict): Activation config of depthwise ConvModule. If it is\n            'default', it will be the same as `act_cfg`. Default: 'default'.\n        pw_norm_cfg (dict): Norm config of pointwise ConvModule. If it is\n            'default', it will be the same as `norm_cfg`. Default: 'default'.\n        pw_act_cfg (dict): Activation config of pointwise ConvModule. If it is\n            'default', it will be the same as `act_cfg`. Default: 'default'.\n        kwargs (optional): Other shared arguments for depthwise and pointwise\n            ConvModule. See ConvModule for ref.\n    \"\"\"\n\n    def __init__(self,\n                 in_channels,\n                 out_channels,\n                 kernel_size,\n                 stride=1,\n                 padding=0,\n                 dilation=1,\n                 norm_cfg=None,\n                 act_cfg=dict(type='ReLU'),\n                 dw_norm_cfg='default',\n                 dw_act_cfg='default',\n                 pw_norm_cfg='default',\n                 pw_act_cfg='default',\n                 **kwargs):\n        super(DepthwiseSeparableConvModule, self).__init__()\n        assert 'groups' not in kwargs, 'groups should not be specified'\n\n        # if norm/activation config of depthwise/pointwise ConvModule is not\n        # specified, use default config.\n        dw_norm_cfg = dw_norm_cfg if dw_norm_cfg != 'default' else norm_cfg\n        dw_act_cfg = dw_act_cfg if dw_act_cfg != 'default' else act_cfg\n        pw_norm_cfg = pw_norm_cfg if pw_norm_cfg != 'default' else norm_cfg\n        pw_act_cfg = pw_act_cfg if pw_act_cfg != 'default' else act_cfg\n\n        # depthwise convolution\n        self.depthwise_conv = ConvModule(\n            in_channels,\n            in_channels,\n            kernel_size,\n            stride=stride,\n            padding=padding,\n            dilation=dilation,\n            groups=in_channels,\n            norm_cfg=dw_norm_cfg,\n            act_cfg=dw_act_cfg,\n            **kwargs)\n\n        self.pointwise_conv = ConvModule(\n            in_channels,\n            out_channels,\n            1,\n            norm_cfg=pw_norm_cfg,\n            act_cfg=pw_act_cfg,\n            **kwargs)\n\n    def forward(self, x):\n        x = self.depthwise_conv(x)\n        x = self.pointwise_conv(x)\n        return x\n", "path": "mmcv/cnn/bricks/depthwise_separable_conv_module.py"}, {"content": "import warnings\n\nimport torch.nn as nn\n\nfrom ..utils import constant_init, kaiming_init\nfrom .activation import build_activation_layer\nfrom .conv import build_conv_layer\nfrom .norm import build_norm_layer\nfrom .padding import build_padding_layer\nfrom .registry import PLUGIN_LAYERS\n\n\n@PLUGIN_LAYERS.register_module()\nclass ConvModule(nn.Module):\n    \"\"\"A conv block that bundles conv/norm/activation layers.\n\n    This block simplifies the usage of convolution layers, which are commonly\n    used with a norm layer (e.g., BatchNorm) and activation layer (e.g., ReLU).\n    It is based upon three build methods: `build_conv_layer()`,\n    `build_norm_layer()` and `build_activation_layer()`.\n\n    Besides, we add some additional features in this module.\n    1. Automatically set `bias` of the conv layer.\n    2. Spectral norm is supported.\n    3. More padding modes are supported. Before PyTorch 1.5, nn.Conv2d only\n    supports zero and circular padding, and we add \"reflect\" padding mode.\n\n    Args:\n        in_channels (int): Same as nn.Conv2d.\n        out_channels (int): Same as nn.Conv2d.\n        kernel_size (int | tuple[int]): Same as nn.Conv2d.\n        stride (int | tuple[int]): Same as nn.Conv2d.\n        padding (int | tuple[int]): Same as nn.Conv2d.\n        dilation (int | tuple[int]): Same as nn.Conv2d.\n        groups (int): Same as nn.Conv2d.\n        bias (bool | str): If specified as `auto`, it will be decided by the\n            norm_cfg. Bias will be set as True if `norm_cfg` is None, otherwise\n            False. Default: \"auto\".\n        conv_cfg (dict): Config dict for convolution layer. Default: None,\n            which means using conv2d.\n        norm_cfg (dict): Config dict for normalization layer. Default: None.\n        act_cfg (dict): Config dict for activation layer.\n            Default: dict(type='ReLU').\n        inplace (bool): Whether to use inplace mode for activation.\n            Default: True.\n        with_spectral_norm (bool): Whether use spectral norm in conv module.\n            Default: False.\n        padding_mode (str): If the `padding_mode` has not been supported by\n            current `Conv2d` in PyTorch, we will use our own padding layer\n            instead. Currently, we support ['zeros', 'circular'] with official\n            implementation and ['reflect'] with our own implementation.\n            Default: 'zeros'.\n        order (tuple[str]): The order of conv/norm/activation layers. It is a\n            sequence of \"conv\", \"norm\" and \"act\". Common examples are\n            (\"conv\", \"norm\", \"act\") and (\"act\", \"conv\", \"norm\").\n            Default: ('conv', 'norm', 'act').\n    \"\"\"\n\n    _abbr_ = 'conv_block'\n\n    def __init__(self,\n                 in_channels,\n                 out_channels,\n                 kernel_size,\n                 stride=1,\n                 padding=0,\n                 dilation=1,\n                 groups=1,\n                 bias='auto',\n                 conv_cfg=None,\n                 norm_cfg=None,\n                 act_cfg=dict(type='ReLU'),\n                 inplace=True,\n                 with_spectral_norm=False,\n                 padding_mode='zeros',\n                 order=('conv', 'norm', 'act')):\n        super(ConvModule, self).__init__()\n        assert conv_cfg is None or isinstance(conv_cfg, dict)\n        assert norm_cfg is None or isinstance(norm_cfg, dict)\n        assert act_cfg is None or isinstance(act_cfg, dict)\n        official_padding_mode = ['zeros', 'circular']\n        self.conv_cfg = conv_cfg\n        self.norm_cfg = norm_cfg\n        self.act_cfg = act_cfg\n        self.inplace = inplace\n        self.with_spectral_norm = with_spectral_norm\n        self.with_explicit_padding = padding_mode not in official_padding_mode\n        self.order = order\n        assert isinstance(self.order, tuple) and len(self.order) == 3\n        assert set(order) == set(['conv', 'norm', 'act'])\n\n        self.with_norm = norm_cfg is not None\n        self.with_activation = act_cfg is not None\n        # if the conv layer is before a norm layer, bias is unnecessary.\n        if bias == 'auto':\n            bias = not self.with_norm\n        self.with_bias = bias\n\n        if self.with_norm and self.with_bias:\n            warnings.warn('ConvModule has norm and bias at the same time')\n\n        if self.with_explicit_padding:\n            pad_cfg = dict(type=padding_mode)\n            self.padding_layer = build_padding_layer(pad_cfg, padding)\n\n        # reset padding to 0 for conv module\n        conv_padding = 0 if self.with_explicit_padding else padding\n        # build convolution layer\n        self.conv = build_conv_layer(\n            conv_cfg,\n            in_channels,\n            out_channels,\n            kernel_size,\n            stride=stride,\n            padding=conv_padding,\n            dilation=dilation,\n            groups=groups,\n            bias=bias)\n        # export the attributes of self.conv to a higher level for convenience\n        self.in_channels = self.conv.in_channels\n        self.out_channels = self.conv.out_channels\n        self.kernel_size = self.conv.kernel_size\n        self.stride = self.conv.stride\n        self.padding = padding\n        self.dilation = self.conv.dilation\n        self.transposed = self.conv.transposed\n        self.output_padding = self.conv.output_padding\n        self.groups = self.conv.groups\n\n        if self.with_spectral_norm:\n            self.conv = nn.utils.spectral_norm(self.conv)\n\n        # build normalization layers\n        if self.with_norm:\n            # norm layer is after conv layer\n            if order.index('norm') > order.index('conv'):\n                norm_channels = out_channels\n            else:\n                norm_channels = in_channels\n            self.norm_name, norm = build_norm_layer(norm_cfg, norm_channels)\n            self.add_module(self.norm_name, norm)\n\n        # build activation layer\n        if self.with_activation:\n            act_cfg_ = act_cfg.copy()\n            # nn.Tanh has no 'inplace' argument\n            if act_cfg_['type'] not in [\n                    'Tanh', 'PReLU', 'Sigmoid', 'HSigmoid', 'Swish'\n            ]:\n                act_cfg_.setdefault('inplace', inplace)\n            self.activate = build_activation_layer(act_cfg_)\n\n        # Use msra init by default\n        self.init_weights()\n\n    @property\n    def norm(self):\n        return getattr(self, self.norm_name)\n\n    def init_weights(self):\n        # 1. It is mainly for customized conv layers with their own\n        #    initialization manners, and we do not want ConvModule to\n        #    overrides the initialization.\n        # 2. For customized conv layers without their own initialization\n        #    manners, they will be initialized by this method with default\n        #    `kaiming_init`.\n        # 3. For PyTorch's conv layers, they will be initialized anyway by\n        #    their own `reset_parameters` methods.\n        if not hasattr(self.conv, 'init_weights'):\n            if self.with_activation and self.act_cfg['type'] == 'LeakyReLU':\n                nonlinearity = 'leaky_relu'\n                a = self.act_cfg.get('negative_slope', 0.01)\n            else:\n                nonlinearity = 'relu'\n                a = 0\n            kaiming_init(self.conv, a=a, nonlinearity=nonlinearity)\n        if self.with_norm:\n            constant_init(self.norm, 1, bias=0)\n\n    def forward(self, x, activate=True, norm=True):\n        for layer in self.order:\n            if layer == 'conv':\n                if self.with_explicit_padding:\n                    x = self.padding_layer(x)\n                x = self.conv(x)\n            elif layer == 'norm' and norm and self.with_norm:\n                x = self.norm(x)\n            elif layer == 'act' and activate and self.with_activation:\n                x = self.activate(x)\n        return x\n", "path": "mmcv/cnn/bricks/conv_module.py"}], "after_files": [{"content": "import torch.nn as nn\n\nfrom .conv_module import ConvModule\n\n\nclass DepthwiseSeparableConvModule(nn.Module):\n    \"\"\"Depthwise separable convolution module.\n\n    See https://arxiv.org/pdf/1704.04861.pdf for details.\n\n    This module can replace a ConvModule with the conv block replaced by two\n    conv block: depthwise conv block and pointwise conv block. The depthwise\n    conv block contains depthwise-conv/norm/activation layers. The pointwise\n    conv block contains pointwise-conv/norm/activation layers. It should be\n    noted that there will be norm/activation layer in the depthwise conv block\n    if `norm_cfg` and `act_cfg` are specified.\n\n    Args:\n        in_channels (int): Number of channels in the input feature map.\n            Same as that in ``nn._ConvNd``.\n        out_channels (int): Number of channels produced by the convolution.\n            Same as that in ``nn._ConvNd``.\n        kernel_size (int | tuple[int]): Size of the convolving kernel.\n            Same as that in ``nn._ConvNd``.\n        stride (int | tuple[int]): Stride of the convolution.\n            Same as that in ``nn._ConvNd``. Default: 1.\n        padding (int | tuple[int]): Zero-padding added to both sides of\n            the input. Same as that in ``nn._ConvNd``. Default: 0.\n        dilation (int | tuple[int]): Spacing between kernel elements.\n            Same as that in ``nn._ConvNd``. Default: 1.\n        norm_cfg (dict): Default norm config for both depthwise ConvModule and\n            pointwise ConvModule. Default: None.\n        act_cfg (dict): Default activation config for both depthwise ConvModule\n            and pointwise ConvModule. Default: dict(type='ReLU').\n        dw_norm_cfg (dict): Norm config of depthwise ConvModule. If it is\n            'default', it will be the same as `norm_cfg`. Default: 'default'.\n        dw_act_cfg (dict): Activation config of depthwise ConvModule. If it is\n            'default', it will be the same as `act_cfg`. Default: 'default'.\n        pw_norm_cfg (dict): Norm config of pointwise ConvModule. If it is\n            'default', it will be the same as `norm_cfg`. Default: 'default'.\n        pw_act_cfg (dict): Activation config of pointwise ConvModule. If it is\n            'default', it will be the same as `act_cfg`. Default: 'default'.\n        kwargs (optional): Other shared arguments for depthwise and pointwise\n            ConvModule. See ConvModule for ref.\n    \"\"\"\n\n    def __init__(self,\n                 in_channels,\n                 out_channels,\n                 kernel_size,\n                 stride=1,\n                 padding=0,\n                 dilation=1,\n                 norm_cfg=None,\n                 act_cfg=dict(type='ReLU'),\n                 dw_norm_cfg='default',\n                 dw_act_cfg='default',\n                 pw_norm_cfg='default',\n                 pw_act_cfg='default',\n                 **kwargs):\n        super(DepthwiseSeparableConvModule, self).__init__()\n        assert 'groups' not in kwargs, 'groups should not be specified'\n\n        # if norm/activation config of depthwise/pointwise ConvModule is not\n        # specified, use default config.\n        dw_norm_cfg = dw_norm_cfg if dw_norm_cfg != 'default' else norm_cfg\n        dw_act_cfg = dw_act_cfg if dw_act_cfg != 'default' else act_cfg\n        pw_norm_cfg = pw_norm_cfg if pw_norm_cfg != 'default' else norm_cfg\n        pw_act_cfg = pw_act_cfg if pw_act_cfg != 'default' else act_cfg\n\n        # depthwise convolution\n        self.depthwise_conv = ConvModule(\n            in_channels,\n            in_channels,\n            kernel_size,\n            stride=stride,\n            padding=padding,\n            dilation=dilation,\n            groups=in_channels,\n            norm_cfg=dw_norm_cfg,\n            act_cfg=dw_act_cfg,\n            **kwargs)\n\n        self.pointwise_conv = ConvModule(\n            in_channels,\n            out_channels,\n            1,\n            norm_cfg=pw_norm_cfg,\n            act_cfg=pw_act_cfg,\n            **kwargs)\n\n    def forward(self, x):\n        x = self.depthwise_conv(x)\n        x = self.pointwise_conv(x)\n        return x\n", "path": "mmcv/cnn/bricks/depthwise_separable_conv_module.py"}, {"content": "import warnings\n\nimport torch.nn as nn\n\nfrom ..utils import constant_init, kaiming_init\nfrom .activation import build_activation_layer\nfrom .conv import build_conv_layer\nfrom .norm import build_norm_layer\nfrom .padding import build_padding_layer\nfrom .registry import PLUGIN_LAYERS\n\n\n@PLUGIN_LAYERS.register_module()\nclass ConvModule(nn.Module):\n    \"\"\"A conv block that bundles conv/norm/activation layers.\n\n    This block simplifies the usage of convolution layers, which are commonly\n    used with a norm layer (e.g., BatchNorm) and activation layer (e.g., ReLU).\n    It is based upon three build methods: `build_conv_layer()`,\n    `build_norm_layer()` and `build_activation_layer()`.\n\n    Besides, we add some additional features in this module.\n    1. Automatically set `bias` of the conv layer.\n    2. Spectral norm is supported.\n    3. More padding modes are supported. Before PyTorch 1.5, nn.Conv2d only\n    supports zero and circular padding, and we add \"reflect\" padding mode.\n\n    Args:\n        in_channels (int): Number of channels in the input feature map.\n            Same as that in ``nn._ConvNd``.\n        out_channels (int): Number of channels produced by the convolution.\n            Same as that in ``nn._ConvNd``.\n        kernel_size (int | tuple[int]): Size of the convolving kernel.\n            Same as that in ``nn._ConvNd``.\n        stride (int | tuple[int]): Stride of the convolution.\n            Same as that in ``nn._ConvNd``.\n        padding (int | tuple[int]): Zero-padding added to both sides of\n            the input. Same as that in ``nn._ConvNd``.\n        dilation (int | tuple[int]): Spacing between kernel elements.\n            Same as that in ``nn._ConvNd``.\n        groups (int): Number of blocked connections from input channels to\n            output channels. Same as that in ``nn._ConvNd``.\n        bias (bool | str): If specified as `auto`, it will be decided by the\n            norm_cfg. Bias will be set as True if `norm_cfg` is None, otherwise\n            False. Default: \"auto\".\n        conv_cfg (dict): Config dict for convolution layer. Default: None,\n            which means using conv2d.\n        norm_cfg (dict): Config dict for normalization layer. Default: None.\n        act_cfg (dict): Config dict for activation layer.\n            Default: dict(type='ReLU').\n        inplace (bool): Whether to use inplace mode for activation.\n            Default: True.\n        with_spectral_norm (bool): Whether use spectral norm in conv module.\n            Default: False.\n        padding_mode (str): If the `padding_mode` has not been supported by\n            current `Conv2d` in PyTorch, we will use our own padding layer\n            instead. Currently, we support ['zeros', 'circular'] with official\n            implementation and ['reflect'] with our own implementation.\n            Default: 'zeros'.\n        order (tuple[str]): The order of conv/norm/activation layers. It is a\n            sequence of \"conv\", \"norm\" and \"act\". Common examples are\n            (\"conv\", \"norm\", \"act\") and (\"act\", \"conv\", \"norm\").\n            Default: ('conv', 'norm', 'act').\n    \"\"\"\n\n    _abbr_ = 'conv_block'\n\n    def __init__(self,\n                 in_channels,\n                 out_channels,\n                 kernel_size,\n                 stride=1,\n                 padding=0,\n                 dilation=1,\n                 groups=1,\n                 bias='auto',\n                 conv_cfg=None,\n                 norm_cfg=None,\n                 act_cfg=dict(type='ReLU'),\n                 inplace=True,\n                 with_spectral_norm=False,\n                 padding_mode='zeros',\n                 order=('conv', 'norm', 'act')):\n        super(ConvModule, self).__init__()\n        assert conv_cfg is None or isinstance(conv_cfg, dict)\n        assert norm_cfg is None or isinstance(norm_cfg, dict)\n        assert act_cfg is None or isinstance(act_cfg, dict)\n        official_padding_mode = ['zeros', 'circular']\n        self.conv_cfg = conv_cfg\n        self.norm_cfg = norm_cfg\n        self.act_cfg = act_cfg\n        self.inplace = inplace\n        self.with_spectral_norm = with_spectral_norm\n        self.with_explicit_padding = padding_mode not in official_padding_mode\n        self.order = order\n        assert isinstance(self.order, tuple) and len(self.order) == 3\n        assert set(order) == set(['conv', 'norm', 'act'])\n\n        self.with_norm = norm_cfg is not None\n        self.with_activation = act_cfg is not None\n        # if the conv layer is before a norm layer, bias is unnecessary.\n        if bias == 'auto':\n            bias = not self.with_norm\n        self.with_bias = bias\n\n        if self.with_norm and self.with_bias:\n            warnings.warn('ConvModule has norm and bias at the same time')\n\n        if self.with_explicit_padding:\n            pad_cfg = dict(type=padding_mode)\n            self.padding_layer = build_padding_layer(pad_cfg, padding)\n\n        # reset padding to 0 for conv module\n        conv_padding = 0 if self.with_explicit_padding else padding\n        # build convolution layer\n        self.conv = build_conv_layer(\n            conv_cfg,\n            in_channels,\n            out_channels,\n            kernel_size,\n            stride=stride,\n            padding=conv_padding,\n            dilation=dilation,\n            groups=groups,\n            bias=bias)\n        # export the attributes of self.conv to a higher level for convenience\n        self.in_channels = self.conv.in_channels\n        self.out_channels = self.conv.out_channels\n        self.kernel_size = self.conv.kernel_size\n        self.stride = self.conv.stride\n        self.padding = padding\n        self.dilation = self.conv.dilation\n        self.transposed = self.conv.transposed\n        self.output_padding = self.conv.output_padding\n        self.groups = self.conv.groups\n\n        if self.with_spectral_norm:\n            self.conv = nn.utils.spectral_norm(self.conv)\n\n        # build normalization layers\n        if self.with_norm:\n            # norm layer is after conv layer\n            if order.index('norm') > order.index('conv'):\n                norm_channels = out_channels\n            else:\n                norm_channels = in_channels\n            self.norm_name, norm = build_norm_layer(norm_cfg, norm_channels)\n            self.add_module(self.norm_name, norm)\n\n        # build activation layer\n        if self.with_activation:\n            act_cfg_ = act_cfg.copy()\n            # nn.Tanh has no 'inplace' argument\n            if act_cfg_['type'] not in [\n                    'Tanh', 'PReLU', 'Sigmoid', 'HSigmoid', 'Swish'\n            ]:\n                act_cfg_.setdefault('inplace', inplace)\n            self.activate = build_activation_layer(act_cfg_)\n\n        # Use msra init by default\n        self.init_weights()\n\n    @property\n    def norm(self):\n        return getattr(self, self.norm_name)\n\n    def init_weights(self):\n        # 1. It is mainly for customized conv layers with their own\n        #    initialization manners, and we do not want ConvModule to\n        #    overrides the initialization.\n        # 2. For customized conv layers without their own initialization\n        #    manners, they will be initialized by this method with default\n        #    `kaiming_init`.\n        # 3. For PyTorch's conv layers, they will be initialized anyway by\n        #    their own `reset_parameters` methods.\n        if not hasattr(self.conv, 'init_weights'):\n            if self.with_activation and self.act_cfg['type'] == 'LeakyReLU':\n                nonlinearity = 'leaky_relu'\n                a = self.act_cfg.get('negative_slope', 0.01)\n            else:\n                nonlinearity = 'relu'\n                a = 0\n            kaiming_init(self.conv, a=a, nonlinearity=nonlinearity)\n        if self.with_norm:\n            constant_init(self.norm, 1, bias=0)\n\n    def forward(self, x, activate=True, norm=True):\n        for layer in self.order:\n            if layer == 'conv':\n                if self.with_explicit_padding:\n                    x = self.padding_layer(x)\n                x = self.conv(x)\n            elif layer == 'norm' and norm and self.with_norm:\n                x = self.norm(x)\n            elif layer == 'act' and activate and self.with_activation:\n                x = self.activate(x)\n        return x\n", "path": "mmcv/cnn/bricks/conv_module.py"}]}