anomalib.models.stfpm

STFPM Model.

Submodules

Package Contents

Classes

Stfpm

PL Lightning Module for the STFPM algorithm.

StfpmLightning

PL Lightning Module for the STFPM algorithm.

class anomalib.models.stfpm.Stfpm(input_size: Tuple[int, int], backbone: str, layers: List[str])[source]

Bases: anomalib.models.components.AnomalyModule

PL Lightning Module for the STFPM algorithm.

Parameters
  • input_size (Tuple[int, int]) – Size of the model input.

  • backbone (str) – Backbone CNN network

  • layers (List[str]) – Layers to extract features from the backbone CNN

training_step(batch, _)

Training Step of STFPM.

For each batch, teacher and student and teacher features are extracted from the CNN.

Parameters
  • batch (Tensor) – Input batch

  • _ – Index of the batch.

Returns

Hierarchical feature map

validation_step(batch, _)

Validation Step of STFPM.

Similar to the training step, student/teacher features are extracted from the CNN for each batch, and anomaly map is computed.

Parameters
  • batch (Tensor) – Input batch

  • _ – Index of the batch.

Returns

Dictionary containing images, anomaly maps, true labels and masks. These are required in validation_epoch_end for feature concatenation.

class anomalib.models.stfpm.StfpmLightning(hparams: Union[omegaconf.DictConfig, omegaconf.ListConfig])[source]

Bases: Stfpm

PL Lightning Module for the STFPM algorithm.

Parameters

hparams (Union[DictConfig, ListConfig]) – Model params

configure_callbacks()

Configure model-specific callbacks.

Note

This method is used for the existing CLI. When PL CLI is introduced, configure callback method will be

deprecated, and callbacks will be configured from either config.yaml file or from CLI.

configure_optimizers() torch.optim.Optimizer

Configures optimizers for each decoder.

Note

This method is used for the existing CLI. When PL CLI is introduced, configure optimizers method will be

deprecated, and optimizers will be configured from either config.yaml file or from CLI.

Returns

Adam optimizer for each decoder

Return type

Optimizer