anomalib.models.patchcore.anomaly_map¶
Anomaly Map Generator for the PatchCore model implementation.
Module Contents¶
Classes¶
Generate Anomaly Heatmap. |
- class anomalib.models.patchcore.anomaly_map.AnomalyMapGenerator(input_size: Union[omegaconf.ListConfig, Tuple], sigma: int = 4)[source]¶
Bases:
torch.nn.ModuleGenerate Anomaly Heatmap.
- compute_anomaly_map(patch_scores: torch.Tensor, feature_map_shape: torch.Size) torch.Tensor[source]¶
Pixel Level Anomaly Heatmap.
- Parameters
patch_scores (torch.Tensor) – Patch-level anomaly scores
feature_map_shape (torch.Size) – 2-D feature map shape (width, height)
- Returns
Map of the pixel-level anomaly scores
- Return type
torch.Tensor
- static compute_anomaly_score(patch_scores: torch.Tensor) torch.Tensor[source]¶
Compute Image-Level Anomaly Score.
- Parameters
patch_scores (torch.Tensor) – Patch-level anomaly scores
- Returns
Image-level anomaly scores
- Return type
torch.Tensor
- forward(**kwargs: torch.Tensor) Tuple[torch.Tensor, torch.Tensor][source]¶
Returns anomaly_map and anomaly_score.
Expects patch_scores keyword to be passed explicitly Expects feature_map_shape keyword to be passed explicitly
Example >>> anomaly_map_generator = AnomalyMapGenerator(input_size=input_size) >>> map, score = anomaly_map_generator(patch_scores=numpy_array, feature_map_shape=feature_map_shape)
- Raises
ValueError – If patch_scores key is not found
- Returns
anomaly_map, anomaly_score
- Return type
Tuple[torch.Tensor, torch.Tensor]