anomalib.models.patchcore

PatchCore model.

Submodules

Package Contents

Classes

Patchcore

PatchcoreLightning Module to train PatchCore algorithm.

PatchcoreLightning

PatchcoreLightning Module to train PatchCore algorithm.

class anomalib.models.patchcore.Patchcore(input_size: Tuple[int, int], backbone: str, layers: List[str], 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

  • 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(self) None

Configure optimizers.

Returns

Do not set optimizers by returning None.

Return type

None

training_step(self, batch, _batch_idx)

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

Apply subsampling to the embedding collected from the training set.

validation_step(self, batch, _)

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.PatchcoreLightning(hparams)[source]

Bases: Patchcore

PatchcoreLightning Module to train PatchCore algorithm.

Parameters

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