anomalib.models.dfkde

Deep Feature Kernel Density Estimation model.

Submodules

Package Contents

Classes

Dfkde

DFKDE: Deep Feature Kernel Density Estimation.

DfkdeLightning

DFKDE: Deep Feature Kernel Density Estimation.

class anomalib.models.dfkde.Dfkde(backbone: str, pre_trained: bool = True, max_training_points: int = 40000, pre_processing: str = 'scale', n_components: int = 16, threshold_steepness: float = 0.05, threshold_offset: int = 12)[source]

Bases: anomalib.models.components.AnomalyModule

DFKDE: Deep Feature Kernel Density Estimation.

Parameters
  • backbone (str) – Pre-trained model backbone.

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

  • max_training_points (int, optional) – Number of training points to fit the KDE model. Defaults to 40000.

  • pre_processing (str, optional) – Preprocess features before passing to KDE. Options are between norm and scale. Defaults to “scale”.

  • n_components (int, optional) – Number of PCA components. Defaults to 16.

  • threshold_steepness (float, optional) – Controls how quickly the value saturates around zero. Defaults to 0.05.

  • threshold_offset (float, optional) – Offset of the density function from 0. Defaults to 12.0.

static configure_optimizers()

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

training_step(batch, _batch_idx)

Training Step of DFKDE. For each batch, features are extracted from the CNN.

Parameters
  • batch (Dict[str, Any]) – Batch containing image filename, image, label and mask

  • _batch_idx – Index of the batch.

Returns

Deep CNN features.

on_validation_start() None

Fit a KDE Model to the embedding collected from the training set.

validation_step(batch, _)

Validation Step of DFKDE.

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

Parameters

batch – Input batch

Returns

Dictionary containing probability, prediction and ground truth values.

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

Bases: Dfkde

DFKDE: Deep Feature Kernel Density Estimation.

Parameters

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