Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def default_config(cls):
config = ResNet.default_config()
config['body/num_blocks'] = [3, 8, 36, 3]
config['body/block/bottleneck'] = True
return config
class ResNeXt18(ResNet):
""" The ResNeXt-18 architecture """
@classmethod
def default_config(cls):
config = ResNet18.default_config()
config['body/block/resnext'] = True
return config
class ResNeXt34(ResNet):
""" The ResNeXt-34 architecture """
@classmethod
def default_config(cls):
config = ResNet34.default_config()
config['body/block/resnext'] = True
return config
class ResNeXt50(ResNet):
""" The ResNeXt-50 architecture """
@classmethod
def default_config(cls):
config = ResNet50.default_config()
config['body/block/resnext'] = True
return config
config['body/num_blocks'] = [2, 2, 2, 2]
config['body/block/bottleneck'] = False
return config
class ResNet34(ResNet):
""" The original ResNet-34 architecture """
@classmethod
def default_config(cls):
config = ResNet.default_config()
config['body/num_blocks'] = [3, 4, 6, 3]
config['body/block/bottleneck'] = False
return config
class ResNet50(ResNet):
""" The original ResNet-50 architecture """
@classmethod
def default_config(cls):
config = ResNet34.default_config()
config['body/block/bottleneck'] = True
return config
class ResNet101(ResNet):
""" The original ResNet-101 architecture """
@classmethod
def default_config(cls):
config = ResNet.default_config()
config['body/num_blocks'] = [3, 4, 23, 3]
config['body/block/bottleneck'] = True
return config
config = ResNet34.default_config()
config['body/block/bottleneck'] = True
return config
class ResNet101(ResNet):
""" The original ResNet-101 architecture """
@classmethod
def default_config(cls):
config = ResNet.default_config()
config['body/num_blocks'] = [3, 4, 23, 3]
config['body/block/bottleneck'] = True
return config
class ResNet152(ResNet):
""" The original ResNet-152 architecture """
@classmethod
def default_config(cls):
config = ResNet.default_config()
config['body/num_blocks'] = [3, 8, 36, 3]
config['body/block/bottleneck'] = True
return config
class ResNeXt18(ResNet):
""" The ResNeXt-18 architecture """
@classmethod
def default_config(cls):
config = ResNet18.default_config()
config['body/block/resnext'] = True
return config
if self.padding:
shortcut = F.pad(shortcut, self.padding)
return self.conv(x) + shortcut
class ResNet18(ResNet):
""" The original ResNet-18 architecture """
@classmethod
def default_config(cls):
config = ResNet.default_config()
config['body/num_blocks'] = [2, 2, 2, 2]
config['body/block/bottleneck'] = False
return config
class ResNet34(ResNet):
""" The original ResNet-34 architecture """
@classmethod
def default_config(cls):
config = ResNet.default_config()
config['body/num_blocks'] = [3, 4, 6, 3]
config['body/block/bottleneck'] = False
return config
class ResNet50(ResNet):
""" The original ResNet-50 architecture """
@classmethod
def default_config(cls):
config = ResNet34.default_config()
config['body/block/bottleneck'] = True
return config
input tensor
skip
skip connection
Returns
-------
nn.Module
"""
kwargs = cls.get_defaults('body', kwargs)
layout, filters, kernel_size = cls.pop(['layout', 'filters', 'kernel_size'], kwargs)
upsample_args = cls.pop('upsample', kwargs)
x = cls.upsample(inputs, filters=filters, name='upsample', **upsample_args, **kwargs)
x = cls.crop(x, skip, data_format=kwargs.get('data_format'))
x = torch.cat([skip, x], dim=1)
x = ResNet.block(x, layout=layout, filters=filters, kernel_size=kernel_size, downsample=0, **kwargs)
return x
def __init__(self, conv, shortcut, padding=None):
super().__init__()
self.conv = conv
self.shortcut = shortcut
self.padding = padding
self.output_shape = get_shape(conv)
def forward(self, x):
""" Make a forward pass """
shortcut = self.shortcut(x) if self.shortcut else x
if self.padding:
shortcut = F.pad(shortcut, self.padding)
return self.conv(x) + shortcut
class ResNet18(ResNet):
""" The original ResNet-18 architecture """
@classmethod
def default_config(cls):
config = ResNet.default_config()
config['body/num_blocks'] = [2, 2, 2, 2]
config['body/block/bottleneck'] = False
return config
class ResNet34(ResNet):
""" The original ResNet-34 architecture """
@classmethod
def default_config(cls):
config = ResNet.default_config()
config['body/num_blocks'] = [3, 4, 6, 3]
config['body/block/bottleneck'] = False
config = ResNet.default_config()
config['body/num_blocks'] = [3, 4, 6, 3]
config['body/block/bottleneck'] = False
return config
class ResNet50(ResNet):
""" The original ResNet-50 architecture """
@classmethod
def default_config(cls):
config = ResNet34.default_config()
config['body/block/bottleneck'] = True
return config
class ResNet101(ResNet):
""" The original ResNet-101 architecture """
@classmethod
def default_config(cls):
config = ResNet.default_config()
config['body/num_blocks'] = [3, 4, 23, 3]
config['body/block/bottleneck'] = True
return config
class ResNet152(ResNet):
""" The original ResNet-152 architecture """
@classmethod
def default_config(cls):
config = ResNet.default_config()
config['body/num_blocks'] = [3, 8, 36, 3]
config['body/block/bottleneck'] = True
def __init__(self, conv, shortcut, padding=None):
super().__init__()
self.conv = conv
self.shortcut = shortcut
self.padding = padding
self.output_shape = get_shape(conv)
def forward(self, x):
""" Make a forward pass """
shortcut = self.shortcut(x) if self.shortcut else x
if self.padding:
shortcut = F.pad(shortcut, self.padding)
return self.conv(x) + shortcut
class ResNet18(ResNet):
""" The original ResNet-18 architecture """
@classmethod
def default_config(cls):
config = ResNet.default_config()
config['body/num_blocks'] = [2, 2, 2, 2]
config['body/block/bottleneck'] = False
return config
class ResNet34(ResNet):
""" The original ResNet-34 architecture """
@classmethod
def default_config(cls):
config = ResNet.default_config()
config['body/num_blocks'] = [3, 4, 6, 3]
config['body/block/bottleneck'] = False
config = ResNet.default_config()
config['body/num_blocks'] = [3, 4, 6, 3]
config['body/block/bottleneck'] = False
return config
class ResNet50(ResNet):
""" The original ResNet-50 architecture """
@classmethod
def default_config(cls):
config = ResNet34.default_config()
config['body/block/bottleneck'] = True
return config
class ResNet101(ResNet):
""" The original ResNet-101 architecture """
@classmethod
def default_config(cls):
config = ResNet.default_config()
config['body/num_blocks'] = [3, 4, 23, 3]
config['body/block/bottleneck'] = True
return config
class ResNet152(ResNet):
""" The original ResNet-152 architecture """
@classmethod
def default_config(cls):
config = ResNet.default_config()
config['body/num_blocks'] = [3, 8, 36, 3]
config['body/block/bottleneck'] = True
Parameters
----------
inputs
input tensor
Returns
-------
nn.Module
"""
kwargs = cls.get_defaults('body', kwargs)
layout, kernel_size = cls.pop(['layout', 'kernel_size'], kwargs)
x, inputs = inputs, None
if downsample:
x = ConvBlock(x, layout='cna', kernel_size=2, strides=2, **kwargs)
x = ResNet.block(x, layout=layout, kernel_size=kernel_size, downsample=False, **kwargs)
return x