ResNetEncoder

class ResNetEncoder(block, layers, num_classes=1000, zero_init_residual=False, groups=1, width_per_group=64, replace_stride_with_dilation=None, norm_layer=None)[source]

A subclass of ResNet defined in torch.

This class overwrites the forward implementation within pytorch to return features of each downsampling level. This is necessary for segmentation.

Methods

resnet

Shortcut method to create customised ResNet.

resnet50

Shortcut method to create ResNet50.

Attributes

Parameters
  • block (Type[Union[torchvision.models.resnet.BasicBlock, torchvision.models.resnet.Bottleneck]]) –

  • layers (List[int]) –

  • num_classes (int) –

  • zero_init_residual (bool) –

  • groups (int) –

  • width_per_group (int) –

  • replace_stride_with_dilation (Optional[List[bool]]) –

  • norm_layer (Optional[Callable[[...], torch.nn.modules.module.Module]]) –

Return type

None

static resnet(num_input_channels, downsampling_levels)[source]

Shortcut method to create customised ResNet.

Parameters
  • num_input_channels (int) – Number of channels in the input images.

  • downsampling_levels (list) – A list of integers where each number defines the number of BottleNeck blocks at each down-sampling level.

Returns

a pytorch model.

Return type

model (torch.nn.Module)

Examples

>>> # instantiate a resnet50
>>> ResNetEncoder.resnet50(
...     num_input_channels,
...     [3, 4, 6, 3],
...     pretrained
... )
static resnet50(num_input_channels)[source]

Shortcut method to create ResNet50.

Parameters

num_input_channels (int) –