anomalib.deploy.inferencers.base_inferencer¶
Base Inferencer for Torch and OpenVINO.
Module Contents¶
Classes¶
Abstract class for the inference. |
- class anomalib.deploy.inferencers.base_inferencer.Inferencer[source]¶
Bases:
abc.ABCAbstract class for the inference.
This is used by both Torch and OpenVINO inference.
- abstract forward(image: Union[numpy.ndarray, torch.Tensor]) Union[numpy.ndarray, torch.Tensor][source]¶
Forward-Pass input to model.
- abstract post_process(predictions: Union[numpy.ndarray, torch.Tensor], meta_data: Optional[Dict[str, Any]]) Dict[str, Any][source]¶
Post-Process.
- predict(image: Union[str, numpy.ndarray, pathlib.Path], meta_data: Optional[Dict[str, Any]] = None) anomalib.post_processing.ImageResult[source]¶
Perform a prediction for a given input image.
The main workflow is (i) pre-processing, (ii) forward-pass, (iii) post-process.
- Parameters
image (Union[str, np.ndarray]) – Input image whose output is to be predicted. It could be either a path to image or numpy array itself.
meta_data – Meta-data information such as shape, threshold.
- Returns
Prediction results to be visualized.
- Return type
- _superimpose_segmentation_mask(meta_data: dict, anomaly_map: numpy.ndarray, image: numpy.ndarray)[source]¶
Superimpose segmentation mask on top of image.
- Parameters
meta_data (dict) – Metadata of the image which contains the image size.
anomaly_map (np.ndarray) – Anomaly map which is used to extract segmentation mask.
image (np.ndarray) – Image on which segmentation mask is to be superimposed.
- Returns
Image with segmentation mask superimposed.
- Return type
np.ndarray
- __call__(image: numpy.ndarray) anomalib.post_processing.ImageResult[source]¶
Call predict on the Image.
- Parameters
image (np.ndarray) – Input Image
- Returns
Prediction results to be visualized.
- Return type
- _normalize(anomaly_maps: Union[torch.Tensor, numpy.ndarray], pred_scores: Union[torch.Tensor, numpy.float32], meta_data: Union[Dict, omegaconf.DictConfig]) Tuple[Union[numpy.ndarray, torch.Tensor], float][source]¶
Applies normalization and resizes the image.
- Parameters
anomaly_maps (Union[Tensor, np.ndarray]) – Predicted raw anomaly map.
pred_scores (Union[Tensor, np.float32]) – Predicted anomaly score
meta_data (Dict) – Meta data. Post-processing step sometimes requires additional meta data such as image shape. This variable comprises such info.
- Returns
- Post processed predictions that are ready to be visualized and
predicted scores.
- Return type
Tuple[Union[np.ndarray, Tensor], float]
- _load_meta_data(path: Optional[Union[str, pathlib.Path]] = None) Union[omegaconf.DictConfig, Dict][source]¶
Loads the meta data from the given path.
- Parameters
path (Optional[Union[str, Path]], optional) – Path to JSON file containing the metadata. If no path is provided, it returns an empty dict. Defaults to None.
- Returns
Dictionary containing the metadata.
- Return type
Union[DictConfig, Dict]