anomalib.models.fastflow.lightning_model

FastFlow Lightning Model Implementation.

Module Contents

Classes

Fastflow

PL Lightning Module for the FastFlow algorithm.

FastflowLightning

PL Lightning Module for the FastFlow algorithm.

class anomalib.models.fastflow.lightning_model.Fastflow(input_size: Tuple[int, int], backbone: str, pre_trained: bool = True, flow_steps: int = 8, conv3x3_only: bool = False, hidden_ratio: float = 1.0)[source]

Bases: anomalib.models.components.AnomalyModule

PL Lightning Module for the FastFlow algorithm.

Parameters
  • input_size (Tuple[int, int]) – Model input size.

  • backbone (str) – Backbone CNN network

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

  • flow_steps (int, optional) – Flow steps.

  • conv3x3_only (bool, optinoal) – Use only conv3x3 in fast_flow model. Defaults to False.

  • hidden_ratio (float, optional) – Ratio to calculate hidden var channels. Defaults to 1.0.

training_step(batch, _)[source]

Forward-pass input and return the loss.

Parameters
  • batch (Tensor) – Input batch

  • _batch_idx – Index of the batch.

Returns

Dictionary containing the loss value.

Return type

STEP_OUTPUT

validation_step(batch, _)[source]

Forward-pass the input and return the anomaly map.

Parameters
  • batch (Tensor) – Input batch

  • _batch_idx – Index of the batch.

Returns

batch dictionary containing anomaly-maps.

Return type

dict

class anomalib.models.fastflow.lightning_model.FastflowLightning(hparams: Union[omegaconf.DictConfig, omegaconf.ListConfig])[source]

Bases: Fastflow

PL Lightning Module for the FastFlow algorithm.

Parameters

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

configure_callbacks()[source]

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[source]

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