fcn

Module containing Fully Convolutional Network (FCN) models.

class DCN(in_channel: int = 512, n_classes: int = 21, variant: Literal['32', '16', '8'] = '32')

Generic DCN defined by the FCN paper. Can construct the DCN32, DCN16 or DCN8 variants defined in the paper.

Based on the example found here: https://github.com/haoran1062/FCN-pytorch/blob/master/FCN.py

variant

Defines which DCN variant this object is, altering the layers constructed and the computational graph. Will be either '32', '16' or '8'. See the FCN paper for details on these variants.

Type:

Literal[‘32’, ‘16’, ‘8’]

n_classes

Number of classes in dataset. Defines number of output classification channels.

Type:

int

relu

Rectified Linear Unit (ReLU) activation layer to be used throughout the network.

Type:

ReLU

Conv1x1

First Conv1x1 layer acting as input to the network from the final output of the encoder and common to all variants.

Type:

Conv2d

bn1

First batch norm layer common to all variants that comes after Conv1x1.

Type:

BatchNorm2d

DC32

De-convolutional layer with stride 32 for DCN32 variant.

Type:

ConvTranspose2d

dbn32

Batch norm layer after DC32.

Type:

BatchNorm2d

Conv1x1_x3

Conv1x1 layer acting as input to the network taking the output from the third layer from the ResNet encoder.

Type:

Conv2d

DC2

De-convolutional layer with stride 2 for DCN16 & DCN8 variants.

Type:

ConvTranspose2d

dbn2

Batch norm layer after DC2.

Type:

BatchNorm2d

DC16

De-convolutional layer with stride 16 for DCN16 variant.

Type:

ConvTranspose2d

dbn16

Batch norm layer after DC16.

Type:

BatchNorm2d

Conv1x1_x2

Conv1x1 layer acting as input to the network taking the output from the second layer from the ResNet encoder.

Type:

Conv2d

DC4

De-convolutional layer with stride 2 for DCN8 variant.

Type:

ConvTranspose2d

dbn4

Batch norm layer after DC4.

Type:

BatchNorm2d

DC8

De-convolutional layer with stride 8 for DCN8 variant.

Type:

ConvTranspose2d

dbn8

Batch norm layer after DC8.

Type:

BatchNorm2d

Parameters:
  • in_channel (int) – Optional; Number of channels in the input layer of the network. Should match the number of output channels (likely feature maps) from the encoder.

  • n_classes (int) – Optional; Number of classes in dataset. Defines number of output classification channels.

  • variant (Literal['32', '16', '8']) – Optional; Flag for which DCN variant to construct. Must be either '32', '16' or '8'. See the FCN paper for details on these variants.

Raises:

NotImplementedError – Raised if variant does not match known types.

forward(x: tuple[Tensor, Tensor, Tensor, Tensor, Tensor]) Tensor

Performs a forward pass of the decoder. Depending on DCN variant, will take multiple inputs throughout pass from the encoder.

Can be called directly as a method (e.g. model.forward()) or when data is parsed to model (e.g. model()).

Parameters:

x (tuple[Tensor, Tensor, Tensor, Tensor, Tensor]) – Input data to network. Should be from a backbone that supports output at multiple points e.g ResNet.

Returns:

Segmentation mask with a channel for each class of the likelihoods the network places on each pixel input x being of that class.

Return type:

Tensor

Raises:

NotImplementedError – Raised if variant does not match known types.

class FCN(criterion: Any, input_size: tuple[int, ...] = (4, 256, 256), n_classes: int = 8, scaler: GradScaler | None = None, backbone_weight_path: str | None = None, freeze_backbone: bool = False, backbone_kwargs: dict[str, Any] = {})

Base Fully Convolutional Network (FCN) class to be subclassed by FCN variants described in the FCN paper.

Based on the example found here: https://github.com/haoran1062/FCN-pytorch/blob/master/FCN.py

Subclasses MinervaModel.

backbone_name

Optional; Name of the backbone within this module to use for the FCN.

Type:

str

decoder_variant

Optional; Flag for which DCN variant to construct. Must be either '32', '16' or '8'. See the FCN paper for details on these variants.

Type:

str

backbone

Backbone of the FCN that takes the imagery input and extracts learned representations.

Type:

Module

decoder

Decoder that takes the learned representations from the backbone encoder and de-convolves to output a classification segmentation mask.

Type:

Module

Parameters:
  • criteriontorch loss function model will use.

  • input_size (tuple[int] | list[int]) – Optional; Defines the shape of the input data in order of number of channels, image width, image height.

  • n_classes (int) – Optional; Number of classes in data to be classified.

  • batch_size (int) – Optional; Number of samples in each batch supplied to the network. Only needed for Decoder, not DCN.

  • backbone_weight_path (str) – Optional; Path to pre-trained weights for the backbone to be loaded.

  • freeze_backbone (bool) – Freezes the weights on the backbone to prevent end-to-end training if using a pre-trained backbone.

  • backbone_kwargs (dict[str, Any]) – Optional; Keyword arguments for the backbone packed up into a dict.

forward(x: Tensor) Tensor

Performs a forward pass of the FCN by using the forward methods of the backbone and feeding its output into the forward for the decoder.

Can be called directly as a method (e.g. model.forward()) or when data is parsed to model (e.g. model()).

Parameters:

x (Tensor) – Input data to network.

Returns:

segmentation mask with a channel for each class of the likelihoods the network places on each pixel input x being of that class.

Return type:

Tensor

class FCN16ResNet18(criterion: Any, input_size: tuple[int, ...] = (4, 256, 256), n_classes: int = 8, scaler: GradScaler | None = None, backbone_weight_path: str | None = None, freeze_backbone: bool = False, backbone_kwargs: dict[str, Any] = {})

Fully Convolutional Network (FCN) using a ResNet18 backbone with a DCN16 decoder.

class FCN16ResNet34(criterion: Any, input_size: tuple[int, ...] = (4, 256, 256), n_classes: int = 8, scaler: GradScaler | None = None, backbone_weight_path: str | None = None, freeze_backbone: bool = False, backbone_kwargs: dict[str, Any] = {})

Fully Convolutional Network (FCN) using a ResNet34 backbone with a DCN16 decoder.

class FCN16ResNet50(criterion: Any, input_size: tuple[int, ...] = (4, 256, 256), n_classes: int = 8, scaler: GradScaler | None = None, backbone_weight_path: str | None = None, freeze_backbone: bool = False, backbone_kwargs: dict[str, Any] = {})

Fully Convolutional Network (FCN) using a ResNet50 backbone with a DCN16 decoder.

class FCN32ResNet18(criterion: Any, input_size: tuple[int, ...] = (4, 256, 256), n_classes: int = 8, scaler: GradScaler | None = None, backbone_weight_path: str | None = None, freeze_backbone: bool = False, backbone_kwargs: dict[str, Any] = {})

Fully Convolutional Network (FCN) using a ResNet18 backbone with a DCN32 decoder.

class FCN32ResNet34(criterion: Any, input_size: tuple[int, ...] = (4, 256, 256), n_classes: int = 8, scaler: GradScaler | None = None, backbone_weight_path: str | None = None, freeze_backbone: bool = False, backbone_kwargs: dict[str, Any] = {})

Fully Convolutional Network (FCN) using a ResNet34 backbone with a DCN32 decoder.

class FCN32ResNet50(criterion: Any, input_size: tuple[int, ...] = (4, 256, 256), n_classes: int = 8, scaler: GradScaler | None = None, backbone_weight_path: str | None = None, freeze_backbone: bool = False, backbone_kwargs: dict[str, Any] = {})

Fully Convolutional Network (FCN) using a ResNet50 backbone with a DCN32 decoder.

class FCN8ResNet101(criterion: Any, input_size: tuple[int, ...] = (4, 256, 256), n_classes: int = 8, scaler: GradScaler | None = None, backbone_weight_path: str | None = None, freeze_backbone: bool = False, backbone_kwargs: dict[str, Any] = {})

Fully Convolutional Network (FCN) using a ResNet101 backbone with a DCN8 decoder.

class FCN8ResNet152(criterion: Any, input_size: tuple[int, ...] = (4, 256, 256), n_classes: int = 8, scaler: GradScaler | None = None, backbone_weight_path: str | None = None, freeze_backbone: bool = False, backbone_kwargs: dict[str, Any] = {})

Fully Convolutional Network (FCN) using a ResNet152 backbone with a DCN8 decoder.

class FCN8ResNet18(criterion: Any, input_size: tuple[int, ...] = (4, 256, 256), n_classes: int = 8, scaler: GradScaler | None = None, backbone_weight_path: str | None = None, freeze_backbone: bool = False, backbone_kwargs: dict[str, Any] = {})

Fully Convolutional Network (FCN) using a ResNet18 backbone with a DCN8 decoder.

class FCN8ResNet34(criterion: Any, input_size: tuple[int, ...] = (4, 256, 256), n_classes: int = 8, scaler: GradScaler | None = None, backbone_weight_path: str | None = None, freeze_backbone: bool = False, backbone_kwargs: dict[str, Any] = {})

Fully Convolutional Network (FCN) using a ResNet34 backbone with a DCN8 decoder.

class FCN8ResNet50(criterion: Any, input_size: tuple[int, ...] = (4, 256, 256), n_classes: int = 8, scaler: GradScaler | None = None, backbone_weight_path: str | None = None, freeze_backbone: bool = False, backbone_kwargs: dict[str, Any] = {})

Fully Convolutional Network (FCN) using a ResNet50 backbone with a DCN8 decoder.