anomalib.models.reverse_distillation.torch_model

PyTorch model for Reverse Distillation.

Module Contents

Classes

ReverseDistillationModel

Reverse Distillation Model.

class anomalib.models.reverse_distillation.torch_model.ReverseDistillationModel(backbone: str, input_size: Tuple[int, int], layers: List[str], anomaly_map_mode: str, pre_trained: bool = True)[source]

Bases: torch.nn.Module

Reverse Distillation Model.

Parameters
  • backbone (str) – Name of the backbone used for encoder and decoder

  • input_size (Tuple[int, int]) – Size of input image

  • layers (List[str]) – Name of layers from which the features are extracted.

  • anomaly_map_mode (str) – Mode used to generate anomaly map. Options are between multiply and add.

  • pre_trained (bool, optional) – Boolean to check whether to use a pre_trained backbone.

forward(images: torch.Tensor) Union[torch.Tensor, Tuple[List[torch.Tensor], List[torch.Tensor]]][source]

Forward-pass images to the network.

During the training mode the model extracts features from encoder and decoder networks. During evaluation mode, it returns the predicted anomaly map.

Parameters

images (Tensor) – Batch of images

Returns

Encoder and decoder features in training mode,

else anomaly maps.

Return type

Union[Tensor, Tuple[List[Tensor],List[Tensor]]]