anomalib.deploy.inferencers.torch_inferencer¶
This module contains Torch inference implementations.
Module Contents¶
Classes¶
PyTorch implementation for the inference. |
- class anomalib.deploy.inferencers.torch_inferencer.TorchInferencer(config: Union[str, pathlib.Path, omegaconf.DictConfig, omegaconf.ListConfig], model_source: Union[str, pathlib.Path, anomalib.models.components.AnomalyModule], meta_data_path: Union[str, pathlib.Path] = None)[source]¶
Bases:
anomalib.deploy.inferencers.base_inferencer.InferencerPyTorch implementation for the inference.
- Parameters
config (Union[str, Path, DictConfig, ListConfig]) – Configurable parameters that are used during the training stage.
model_source (Union[str, Path, AnomalyModule]) – Path to the model ckpt file or the Anomaly model.
meta_data_path (Union[str, Path], optional) – Path to metadata file. If none, it tries to load the params from the model state_dict. Defaults to None.
- _load_meta_data(path: Optional[Union[str, pathlib.Path]] = None) Union[Dict, omegaconf.DictConfig][source]¶
Load metadata from file or from model state dict.
- Parameters
path (Optional[Union[str, Path]], optional) – Path to metadata file. If none, it tries to load the params from the model state_dict. Defaults to None.
- Returns
Dictionary containing the meta_data.
- Return type
Dict
- load_model(path: Union[str, pathlib.Path]) anomalib.models.components.AnomalyModule[source]¶
Load the PyTorch model.
- Parameters
path (Union[str, Path]) – Path to model ckpt file.
- Returns
PyTorch Lightning model.
- Return type
- pre_process(image: numpy.ndarray) torch.Tensor[source]¶
Pre process the input image by applying transformations.
- Parameters
image (np.ndarray) – Input image
- Returns
pre-processed image.
- Return type
Tensor
- forward(image: torch.Tensor) torch.Tensor[source]¶
Forward-Pass input tensor to the model.
- Parameters
image (Tensor) – Input tensor.
- Returns
Output predictions.
- Return type
Tensor
- post_process(predictions: torch.Tensor, meta_data: Optional[Union[Dict, omegaconf.DictConfig]] = None) Dict[str, Any][source]¶
Post process the output predictions.
- Parameters
predictions (Tensor) – Raw output predicted by the model.
meta_data (Dict, optional) – Meta data. Post-processing step sometimes requires additional meta data such as image shape. This variable comprises such info. Defaults to None.
- Returns
Post processed prediction results.
- Return type
Dict[str, Union[str, float, np.ndarray]]