anomalib.models.cflow.lightning_model

CFLOW: Real-Time Unsupervised Anomaly Detection via Conditional Normalizing Flows.

https://arxiv.org/pdf/2107.12571v1.pdf

Module Contents

Classes

Cflow

PL Lightning Module for the CFLOW algorithm.

CflowLightning

PL Lightning Module for the CFLOW algorithm.

class anomalib.models.cflow.lightning_model.Cflow(input_size: Tuple[int, int], backbone: str, layers: List[str], fiber_batch_size: int = 64, decoder: str = 'freia-cflow', condition_vector: int = 128, coupling_blocks: int = 8, clamp_alpha: float = 1.9, permute_soft: bool = False, lr: float = 0.0001)[source]

Bases: anomalib.models.components.AnomalyModule

PL Lightning Module for the CFLOW algorithm.

configure_optimizers(self) 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

training_step(self, batch, _)[source]

Training Step of CFLOW.

For each batch, decoder layers are trained with a dynamic fiber batch size. Training step is performed manually as multiple training steps are involved

per batch of input images

Parameters
  • batch – Input batch

  • _ – Index of the batch.

Returns

Loss value for the batch

validation_step(self, batch, _)[source]

Validation Step of CFLOW.

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

Parameters
  • batch – 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.cflow.lightning_model.CflowLightning(hparams: Union[omegaconf.DictConfig, omegaconf.ListConfig])[source]

Bases: Cflow

PL Lightning Module for the CFLOW algorithm.

Parameters

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

configure_callbacks(self)[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.