anomalib.models.dfm.lightning_model

DFM: Deep Feature Kernel Density Estimation.

Module Contents

Classes

Dfm

DFM: Deep Featured Kernel Density Estimation.

DfmLightning

DFM: Deep Featured Kernel Density Estimation.

Attributes

anomalib.models.dfm.lightning_model.logger[source]
class anomalib.models.dfm.lightning_model.Dfm(backbone: str, layer: str, pre_trained: bool = True, pooling_kernel_size: int = 4, pca_level: float = 0.97, score_type: str = 'fre')[source]

Bases: anomalib.models.components.AnomalyModule

DFM: Deep Featured Kernel Density Estimation.

Parameters
  • backbone (str) – Backbone CNN network

  • layer (str) – Layer to extract features from the backbone CNN

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

  • pooling_kernel_size (int, optional) – Kernel size to pool features extracted from the CNN. Defaults to 4.

  • pca_level (float, optional) – Ratio from which number of components for PCA are calculated. Defaults to 0.97.

  • score_type (str, optional) – Scoring type. Options are fre and nll. Defaults to “fre”.

  • nll – for Gaussian modeling, fre: pca feature reconstruction error

static configure_optimizers() None[source]

DFM doesn’t require optimization, therefore returns no optimizers.

training_step(batch, _)[source]

Training Step of DFM.

For each batch, features are extracted from the CNN.

Parameters
  • batch (Dict[str, Tensor]) – Input batch

  • _ – Index of the batch.

Returns

Deep CNN features.

on_validation_start() None[source]

Fit a PCA transformation and a Gaussian model to dataset.

validation_step(batch, _)[source]

Validation Step of DFM.

Similar to the training step, features are extracted from the CNN for each batch.

Parameters

batch (List[Dict[str, Any]]) – Input batch

Returns

Dictionary containing FRE anomaly scores and ground-truth.

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

Bases: Dfm

DFM: Deep Featured Kernel Density Estimation.

Parameters

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