anomalib.models.patchcore.lightning_model

Towards Total Recall in Industrial Anomaly Detection.

Paper https://arxiv.org/abs/2106.08265.

Module Contents

Classes

Patchcore

PatchcoreLightning Module to train PatchCore algorithm.

PatchcoreLightning

PatchcoreLightning Module to train PatchCore algorithm.

Attributes

anomalib.models.patchcore.lightning_model.logger[source]
class anomalib.models.patchcore.lightning_model.Patchcore(input_size: Tuple[int, int], backbone: str, layers: List[str], pre_trained: bool = True, coreset_sampling_ratio: float = 0.1, num_neighbors: int = 9)[source]

Bases: anomalib.models.components.AnomalyModule

PatchcoreLightning Module to train PatchCore 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

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

  • coreset_sampling_ratio (float, optional) – Coreset sampling ratio to subsample embedding. Defaults to 0.1.

  • num_neighbors (int, optional) – Number of nearest neighbors. Defaults to 9.

configure_optimizers() None[source]

Configure optimizers.

Returns

Do not set optimizers by returning None.

Return type

None

training_step(batch, _batch_idx)[source]

Generate feature embedding of the batch.

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

  • _batch_idx (int) – Batch Index

Returns

Embedding Vector

Return type

Dict[str, np.ndarray]

on_validation_start() None[source]

Apply subsampling to the embedding collected from the training set.

validation_step(batch, _)[source]

Get batch of anomaly maps from input image batch.

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

  • _ (int) – Batch Index

Returns

Image filenames, test images, GT and predicted label/masks

Return type

Dict[str, Any]

class anomalib.models.patchcore.lightning_model.PatchcoreLightning(hparams)[source]

Bases: Patchcore

PatchcoreLightning Module to train PatchCore algorithm.

Parameters

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