MCPcopy
hub / github.com/Fafa-DL/Awesome-Backbones / __init__

Method __init__

configs/common/conv_module.py:57–133  ·  view source on GitHub ↗
(self,
                 in_channels,
                 out_channels,
                 kernel_size,
                 stride=1,
                 padding=0,
                 dilation=1,
                 groups=1,
                 bias='auto',
                 conv_cfg=None,
                 norm_cfg=None,
                 act_cfg=dict(type='ReLU'),
                 inplace=True,
                 with_spectral_norm=False,
                 padding_mode='zeros',
                 order=('conv', 'norm', 'act'))

Source from the content-addressed store, hash-verified

55 Default: ('conv', 'norm', 'act').
56 """
57 def __init__(self,
58 in_channels,
59 out_channels,
60 kernel_size,
61 stride=1,
62 padding=0,
63 dilation=1,
64 groups=1,
65 bias='auto',
66 conv_cfg=None,
67 norm_cfg=None,
68 act_cfg=dict(type='ReLU'),
69 inplace=True,
70 with_spectral_norm=False,
71 padding_mode='zeros',
72 order=('conv', 'norm', 'act')):
73 super(ConvModule, self).__init__()
74 assert conv_cfg is None or isinstance(conv_cfg, dict)
75 assert norm_cfg is None or isinstance(norm_cfg, dict)
76 assert act_cfg is None or isinstance(act_cfg, dict)
77 official_padding_mode = ['zeros', 'circular']
78 self.conv_cfg = copy.deepcopy(conv_cfg)
79 self.norm_cfg = copy.deepcopy(norm_cfg)
80 self.act_cfg = copy.deepcopy(act_cfg)
81 self.inplace = inplace
82 self.with_spectral_norm = with_spectral_norm
83 self.with_explicit_padding = padding_mode not in official_padding_mode
84 self.order = order
85 assert isinstance(self.order, tuple) and len(self.order) == 3
86 assert set(order) == set(['conv', 'norm', 'act'])
87
88 self.with_norm = norm_cfg is not None
89 self.with_activation = act_cfg is not None
90
91 # if the conv layer is before a norm layer, bias is unnecessary.
92 if bias == 'auto':
93 bias = not self.with_norm
94 self.with_bias = bias
95
96 if self.with_explicit_padding:
97 pad_cfg = dict(type=padding_mode)
98 self.padding_layer = build_padding_layer(pad_cfg, padding)
99
100 conv_padding = 0 if self.with_explicit_padding else padding
101
102 self.conv = build_conv_layer(
103 conv_cfg,
104 in_channels,
105 out_channels,
106 kernel_size,
107 stride=stride,
108 padding=conv_padding,
109 dilation=dilation,
110 groups=groups,
111 bias=bias)
112
113 if self.with_spectral_norm:
114 self.conv = nn.utils.spectral_norm(self.conv)

Callers

nothing calls this directly

Calls 5

init_weightsMethod · 0.95
build_padding_layerFunction · 0.90
build_conv_layerFunction · 0.90
build_norm_layerFunction · 0.90
build_activation_layerFunction · 0.90

Tested by

no test coverage detected