models.backbones package

Submodules

models.backbones.VGG module

Model definition adapted from: https://github.com/pytorch/vision/blob/master/torchvision/models/vgg.py

class VGG(features, num_classes=1000, **kwargs)[source]

Bases: Module

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
make_layers(cfg, batch_norm=False)[source]
vgg11(pretrained=False, **kwargs)[source]

VGG 11-layer model (configuration “A”)

Parameters:

pretrained (bool) – If True, returns a model pre-trained on ImageNet

vgg11_bn(pretrained=False, **kwargs)[source]

VGG 11-layer model (configuration “A”) with batch normalization

Parameters:

pretrained (bool) – If True, returns a model pre-trained on ImageNet

vgg13(pretrained=False, **kwargs)[source]

VGG 13-layer model (configuration “B”)

Parameters:

pretrained (bool) – If True, returns a model pre-trained on ImageNet

vgg13_bn(pretrained=False, **kwargs)[source]

VGG 13-layer model (configuration “B”) with batch normalization

Parameters:

pretrained (bool) – If True, returns a model pre-trained on ImageNet

vgg16(pretrained=False, **kwargs)[source]

VGG 16-layer model (configuration “D”)

Parameters:

pretrained (bool) – If True, returns a model pre-trained on ImageNet

vgg16_bn(pretrained=False, **kwargs)[source]

VGG 16-layer model (configuration “D”) with batch normalization

Parameters:

pretrained (bool) – If True, returns a model pre-trained on ImageNet

vgg19(pretrained=False, **kwargs)[source]

VGG 19-layer model (configuration “E”)

Parameters:

pretrained (bool) – If True, returns a model pre-trained on ImageNet

vgg19_bn(pretrained=False, **kwargs)[source]

VGG 19-layer model (configuration ‘E’) with batch normalization

Parameters:

pretrained (bool) – If True, returns a model pre-trained on ImageNet

models.backbones.adaptive_unet module

class Adaptive_Unet(out_channels=4, features=[32, 64, 128, 256])[source]

Bases: Module

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
decoding_block(in_c, out_c)[source]
encoding_block(in_c, out_c)[source]
encoding_block1(in_c, out_c)[source]

models.backbones.baby_cnn module

CNN with 3 conv layers and a fully connected classification layer

class CNN_basic(**kwargs)[source]

Bases: Module

Simple feed forward convolutional neural network

expected_input_size

Expected input size (width, height)

Type:

tuple(int,int)

conv1
Type:

torch.nn.Sequential

conv2
Type:

torch.nn.Sequential

conv3

Convolutional layers of the network

Type:

torch.nn.Sequential

fc

Final classification fully connected layer

Type:

torch.nn.Linear

forward(x)[source]

Computes forward pass on the network

Parameters:

x (Variable) – Sample to run forward pass on. (input to the model)

Returns:

Activations of the fully connected layer

Return type:

Variable

training: bool

models.backbones.backboned_unet module

class Unet(backbone_name='resnet50', pretrained=False, encoder_freeze=False, num_classes=21, decoder_filters=(256, 128, 64, 32, 16), parametric_upsampling=True, shortcut_features='default', decoder_use_batchnorm=True)[source]

Bases: Module

U-Net (https://arxiv.org/pdf/1505.04597.pdf) implementation with pre-trained torchvision backbones.

forward(*input)[source]

Forward propagation in U-Net.

forward_backbone(x)[source]

Forward propagation in backbone encoder network.

freeze_encoder()[source]

Freezing encoder parameters, the newly initialized decoder parameters are remaining trainable.

infer_skip_channels()[source]

Getting the number of channels at skip connections and at the output of the encoder.

training: bool
class UnetDownModule(in_channels, out_channels, downsample=True)[source]

Bases: Module

U-Net downsampling block.

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class UnetEncoder(num_channels)[source]

Bases: Module

U-Net encoder. https://arxiv.org/pdf/1505.04597.pdf

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class UpsampleBlock(ch_in, ch_out=None, skip_in=0, use_bn=True, parametric=False)[source]

Bases: Module

forward(x, skip_connection=None)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
get_backbone(name, pretrained=True)[source]

Loading backbone, defining names for skip-connections and encoder output.

models.backbones.deeplabv3 module

class DeepLabV3(model_name, pretrained, num_classes, **kwargs)[source]

Bases: Module

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
deeplabv3(num_classes, **kwargs)[source]
deeplabv3_builder(model_name, output_channels, pretrained=False, resume=None, cityscapes=False, **kwargs)[source]
deeplabv3_resnet101_os16(num_classes, **kwargs)[source]
deeplabv3_resnet152_os16(num_classes, **kwargs)[source]
deeplabv3_resnet18_os16(num_classes, **kwargs)[source]
deeplabv3_resnet18_os8(num_classes, **kwargs)[source]
deeplabv3_resnet34_os16(num_classes, **kwargs)[source]
deeplabv3_resnet34_os8(num_classes, **kwargs)[source]
deeplabv3_resnet50_os16(num_classes, **kwargs)[source]
get_cityscapes_model_path(**kwargs)[source]

models.backbones.deeplabv3_aspp module

class ASPP(num_classes)[source]

Bases: Module

forward(feature_map)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class ASPP_Bottleneck(num_classes)[source]

Bases: Module

forward(feature_map)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool

models.backbones.deeplabv3_resnet module

class BasicBlock(in_channels, channels, stride=1, dilation=1)[source]

Bases: Module

expansion = 1
forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class Bottleneck(in_channels, channels, stride=1, dilation=1)[source]

Bases: Module

expansion = 4
forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
ResNet101_OS16(pretrained)[source]
ResNet152_OS16(pretrained)[source]
ResNet18_OS16(pretrained)[source]
ResNet18_OS8(pretrained)[source]
ResNet34_OS16(pretrained)[source]
ResNet34_OS8(pretrained)[source]
ResNet50_OS16(pretrained)[source]
class ResNet_BasicBlock_OS16(num_layers, pretrained=False)[source]

Bases: Module

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class ResNet_BasicBlock_OS8(num_layers, pretrained=False)[source]

Bases: Module

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class ResNet_Bottleneck_OS16(num_layers, pretrained=False)[source]

Bases: Module

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
make_layer(block, in_channels, channels, num_blocks, stride=1, dilation=1)[source]

models.backbones.doc_ufcn module

class Doc_ufcn(out_channels=4, features=[32, 64, 128, 256])[source]

Bases: Module

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
decoding_block(in_c, out_c)[source]
dil_block(in_c, out_c)[source]
encoding_block(in_c, out_c)[source]

models.backbones.resnet module

Model definition adapted from: https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py

class ResNet(block: Type[Union[BasicBlock, Bottleneck]], layers: List[int], replace_stride_with_dilation: Optional[List[bool]] = None, **kwargs)[source]

Bases: Module

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class ResNet101(**kwargs)[source]

Bases: ResNet

training: bool
class ResNet152(**kwargs)[source]

Bases: ResNet

training: bool
class ResNet18(**kwargs)[source]

Bases: ResNet

training: bool
class ResNet34(**kwargs)[source]

Bases: ResNet

training: bool
class ResNet50(**kwargs)[source]

Bases: ResNet

training: bool
conv3x3(in_planes, out_planes, stride=1)[source]

3x3 convolution with padding

models.backbones.resnetdd module

Model definition adapted from: https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py

class ResNet(block, layers, num_classes=1000, ablate=False, **kwargs)[source]

Bases: Module

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
conv3x3(in_planes, out_planes, stride=1)[source]

3x3 convolution with padding

resnet101(pretrained=False, **kwargs)[source]

Constructs a _ResNet-101 model. :param pretrained: If True, returns a model pre-trained on ImageNet :type pretrained: bool

resnet152(pretrained=False, **kwargs)[source]

Constructs a _ResNet-152 model. :param pretrained: If True, returns a model pre-trained on ImageNet :type pretrained: bool

resnet18(pretrained=False, **kwargs)[source]

Constructs a _ResNet-18 model. :param pretrained: If True, returns a model pre-trained on ImageNet :type pretrained: bool

resnet34(pretrained=False, **kwargs)[source]

Constructs a _ResNet-34 model. :param pretrained: If True, returns a model pre-trained on ImageNet :type pretrained: bool

resnet50(pretrained=False, **kwargs)[source]

Constructs a _ResNet-50 model. :param pretrained: If True, returns a model pre-trained on ImageNet :type pretrained: bool

models.backbones.segnet module

class SegNet(num_classes, pretrained=False, **kwargs)[source]

Bases: Module

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
initialize_weights(*models)[source]

models.backbones.unet module

class Baby_UNet[source]

Bases: UNet

training: bool
class DoubleConv(in_ch: int, out_ch: int)[source]

Bases: Module

[ Conv2d => BatchNorm (optional) => ReLU ] x 2.

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class Down(in_ch: int, out_ch: int)[source]

Bases: Module

Downscale with MaxPool => DoubleConvolution block.

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class OldUNet(num_classes: int, input_channels: int = 3, num_layers: int = 5, features_start: int = 64, bilinear: bool = False)[source]

Bases: Module

Paper: U-Net: Convolutional Networks for Biomedical Image Segmentation Paper authors: Olaf Ronneberger, Philipp Fischer, Thomas Brox Implemented by:

Parameters:
  • num_classes – Number of output classes required

  • input_channels – Number of channels in input images (default 3)

  • num_layers – Number of layers in each side of U-net (default 5)

  • features_start – Number of features in first layer (default 64)

  • bilinear – Whether to use bilinear interpolation or transposed convolutions (default) for upsampling.

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class UNet(input_channels: int = 3, num_layers: int = 5, features_start: int = 64, bilinear: bool = False)[source]

Bases: Module

Paper: U-Net: Convolutional Networks for Biomedical Image Segmentation

Paper authors: Olaf Ronneberger, Philipp Fischer, Thomas Brox

Implemented by:

Parameters:
  • num_classes – Number of output classes required

  • input_channels – Number of channels in input images (default 3)

  • num_layers – Number of layers in each side of U-net (default 5)

  • features_start – Number of features in first layer (default 64)

  • bilinear – Whether to use bilinear interpolation or transposed convolutions (default) for upsampling.

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class UNet16(num_classes=4)[source]

Bases: UNetNajoua

training: bool
class UNet32(num_classes=4)[source]

Bases: UNetNajoua

training: bool
class UNet64(num_classes=4)[source]

Bases: UNetNajoua

training: bool
class UNetNajoua(num_classes=4, features=[16, 32])[source]

Bases: Module

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class Up(in_ch: int, out_ch: int, bilinear: bool = False)[source]

Bases: Module

Upsampling (by either bilinear interpolation or transpose convolutions) followed by concatenation of feature map from contracting path, followed by DoubleConv.

forward(x1, x2)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
encoding_block(in_c, out_c)[source]
one_conv1(in_c, out_c)[source]
one_conv2(in_c, out_c)[source]

Module contents