(self,
in_channels=3,
num_channels=(32, 64, 128),
num_blocks=(3, 21),
dilations=(2, 4),
reductions=(8, 16),
conv_cfg=None,
norm_cfg=dict(type='BN', requires_grad=True),
act_cfg=dict(type='PReLU'),
norm_eval=False,
with_cp=False,
pretrained=None,
init_cfg=None)
| 217 | """ |
| 218 | |
| 219 | def __init__(self, |
| 220 | in_channels=3, |
| 221 | num_channels=(32, 64, 128), |
| 222 | num_blocks=(3, 21), |
| 223 | dilations=(2, 4), |
| 224 | reductions=(8, 16), |
| 225 | conv_cfg=None, |
| 226 | norm_cfg=dict(type='BN', requires_grad=True), |
| 227 | act_cfg=dict(type='PReLU'), |
| 228 | norm_eval=False, |
| 229 | with_cp=False, |
| 230 | pretrained=None, |
| 231 | init_cfg=None): |
| 232 | |
| 233 | super(CGNet, self).__init__(init_cfg) |
| 234 | |
| 235 | assert not (init_cfg and pretrained), \ |
| 236 | 'init_cfg and pretrained cannot be setting at the same time' |
| 237 | if isinstance(pretrained, str): |
| 238 | warnings.warn('DeprecationWarning: pretrained is a deprecated, ' |
| 239 | 'please use "init_cfg" instead') |
| 240 | self.init_cfg = dict(type='Pretrained', checkpoint=pretrained) |
| 241 | elif pretrained is None: |
| 242 | if init_cfg is None: |
| 243 | self.init_cfg = [ |
| 244 | dict(type='Kaiming', layer=['Conv2d', 'Linear']), |
| 245 | dict( |
| 246 | type='Constant', |
| 247 | val=1, |
| 248 | layer=['_BatchNorm', 'GroupNorm']), |
| 249 | dict(type='Constant', val=0, layer='PReLU') |
| 250 | ] |
| 251 | else: |
| 252 | raise TypeError('pretrained must be a str or None') |
| 253 | |
| 254 | self.in_channels = in_channels |
| 255 | self.num_channels = num_channels |
| 256 | assert isinstance(self.num_channels, tuple) and len( |
| 257 | self.num_channels) == 3 |
| 258 | self.num_blocks = num_blocks |
| 259 | assert isinstance(self.num_blocks, tuple) and len(self.num_blocks) == 2 |
| 260 | self.dilations = dilations |
| 261 | assert isinstance(self.dilations, tuple) and len(self.dilations) == 2 |
| 262 | self.reductions = reductions |
| 263 | assert isinstance(self.reductions, tuple) and len(self.reductions) == 2 |
| 264 | self.conv_cfg = conv_cfg |
| 265 | self.norm_cfg = norm_cfg |
| 266 | self.act_cfg = act_cfg |
| 267 | if 'type' in self.act_cfg and self.act_cfg['type'] == 'PReLU': |
| 268 | self.act_cfg['num_parameters'] = num_channels[0] |
| 269 | self.norm_eval = norm_eval |
| 270 | self.with_cp = with_cp |
| 271 | |
| 272 | cur_channels = in_channels |
| 273 | self.stem = nn.ModuleList() |
| 274 | for i in range(3): |
| 275 | self.stem.append( |
| 276 | ConvModule( |
no test coverage detected