anomalib.models.reverse_distillation.components.de_resnet

Torch model defining the decoder.

Module Contents

Classes

DecoderBasicBlock

Basic block for decoder ResNet architecture.

DecoderBottleneck

Bottleneck for Decoder.

ResNet

ResNet model for decoder.

Functions

_resnet(→ ResNet)

de_resnet18(→ ResNet)

ResNet-18 model.

de_resnet34(→ ResNet)

ResNet-34 model.

de_resnet50(→ ResNet)

ResNet-50 model.

de_resnet101(→ ResNet)

ResNet-101 model.

de_resnet152(→ ResNet)

ResNet-152 model.

de_resnext50_32x4d(→ ResNet)

ResNeXt-50 32x4d model.

de_resnext101_32x8d(→ ResNet)

ResNeXt-101 32x8d model.

de_wide_resnet50_2(→ ResNet)

Wide ResNet-50-2 model.

de_wide_resnet101_2(→ ResNet)

Wide ResNet-101-2 model.

get_decoder(→ ResNet)

Get decoder model based on the name of the backbone.

class anomalib.models.reverse_distillation.components.de_resnet.DecoderBasicBlock(inplanes: int, planes: int, stride: int = 1, upsample: Optional[torch.nn.Module] = None, groups: int = 1, base_width: int = 64, dilation: int = 1, norm_layer: Optional[Callable[Ellipsis, torch.nn.Module]] = None)[source]

Bases: torch.nn.Module

Basic block for decoder ResNet architecture.

Parameters
  • inplanes (int) – Number of input channels.

  • planes (int) – Number of output channels.

  • stride (int, optional) – Stride for convolution and de-convolution layers. Defaults to 1.

  • upsample (Optional[nn.Module], optional) – Module used for upsampling output. Defaults to None.

  • groups (int, optional) – Number of blocked connections from input channels to output channels. Defaults to 1.

  • base_width (int, optional) – Number of layers in each intermediate convolution layer. Defaults to 64.

  • dilation (int, optional) – Spacing between kernel elements. Defaults to 1.

  • norm_layer (Optional[Callable[..., nn.Module]], optional) – Batch norm layer to use.Defaults to None.

Raises
  • ValueError – If groups are not equal to 1 and base width is not 64.

  • NotImplementedError – If dilation is greater than 1.

expansion :int = 1[source]
forward(batch: torch.Tensor) torch.Tensor[source]

Forward-pass of de-resnet block.

class anomalib.models.reverse_distillation.components.de_resnet.DecoderBottleneck(inplanes: int, planes: int, stride: int = 1, upsample: Optional[torch.nn.Module] = None, groups: int = 1, base_width: int = 64, dilation: int = 1, norm_layer: Optional[Callable[Ellipsis, torch.nn.Module]] = None)[source]

Bases: torch.nn.Module

Bottleneck for Decoder.

Parameters
  • inplanes (int) – Number of input channels.

  • planes (int) – Number of output channels.

  • stride (int, optional) – Stride for convolution and de-convolution layers. Defaults to 1.

  • upsample (Optional[nn.Module], optional) – Module used for upsampling output. Defaults to None.

  • groups (int, optional) – Number of blocked connections from input channels to output channels. Defaults to 1.

  • base_width (int, optional) – Number of layers in each intermediate convolution layer. Defaults to 64.

  • dilation (int, optional) – Spacing between kernel elements. Defaults to 1.

  • norm_layer (Optional[Callable[..., nn.Module]], optional) – Batch norm layer to use.Defaults to None.

expansion :int = 4[source]
forward(batch: torch.Tensor) torch.Tensor[source]

Forward-pass of de-resnet bottleneck block.

class anomalib.models.reverse_distillation.components.de_resnet.ResNet(block: Type[Union[DecoderBasicBlock, DecoderBottleneck]], layers: List[int], zero_init_residual: bool = False, groups: int = 1, width_per_group: int = 64, norm_layer: Optional[Callable[Ellipsis, torch.nn.Module]] = None)[source]

Bases: torch.nn.Module

ResNet model for decoder.

Parameters
  • block (Type[Union[DecoderBasicBlock, DecoderBottleneck]]) – Type of block to use in a layer.

  • layers (List[int]) – List to specify number for blocks per layer.

  • zero_init_residual (bool, optional) – If true, initializes the last batch norm in each layer to zero. Defaults to False.

  • groups (int, optional) – Number of blocked connections per layer from input channels to output channels. Defaults to 1.

  • width_per_group (int, optional) – Number of layers in each intermediate convolution layer.. Defaults to 64.

  • norm_layer (Optional[Callable[..., nn.Module]], optional) – Batch norm layer to use. Defaults to None.

_make_layer(block: Type[Union[DecoderBasicBlock, DecoderBottleneck]], planes: int, blocks: int, stride: int = 1) torch.nn.Sequential[source]
forward(batch: torch.Tensor) List[torch.Tensor][source]

Forward pass for Decoder ResNet. Returns list of features.

anomalib.models.reverse_distillation.components.de_resnet._resnet(block: Type[Union[DecoderBasicBlock, DecoderBottleneck]], layers: List[int], **kwargs: Any) ResNet[source]
anomalib.models.reverse_distillation.components.de_resnet.de_resnet18() ResNet[source]

ResNet-18 model.

anomalib.models.reverse_distillation.components.de_resnet.de_resnet34() ResNet[source]

ResNet-34 model.

anomalib.models.reverse_distillation.components.de_resnet.de_resnet50() ResNet[source]

ResNet-50 model.

anomalib.models.reverse_distillation.components.de_resnet.de_resnet101() ResNet[source]

ResNet-101 model.

anomalib.models.reverse_distillation.components.de_resnet.de_resnet152() ResNet[source]

ResNet-152 model.

anomalib.models.reverse_distillation.components.de_resnet.de_resnext50_32x4d() ResNet[source]

ResNeXt-50 32x4d model.

anomalib.models.reverse_distillation.components.de_resnet.de_resnext101_32x8d() ResNet[source]

ResNeXt-101 32x8d model.

anomalib.models.reverse_distillation.components.de_resnet.de_wide_resnet50_2() ResNet[source]

Wide ResNet-50-2 model.

anomalib.models.reverse_distillation.components.de_resnet.de_wide_resnet101_2() ResNet[source]

Wide ResNet-101-2 model.

anomalib.models.reverse_distillation.components.de_resnet.get_decoder(name: str) ResNet[source]

Get decoder model based on the name of the backbone.

Parameters

name (str) – Name of the backbone.

Returns

Decoder ResNet architecture.

Return type

ResNet