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