anomalib.utils.sweep.helpers.inference

Utils to help compute inference statistics.

Module Contents

Classes

MockImageLoader

Create mock images for inference on CPU based on the specifics of the original torch test dataset.

Functions

get_meta_data(model: anomalib.models.components.AnomalyModule, input_size: Tuple[int, int]) → Dict

Get meta data for inference.

get_torch_throughput(config: Union[omegaconf.DictConfig, omegaconf.ListConfig], model: anomalib.models.components.AnomalyModule, test_dataset: torch.utils.data.DataLoader, meta_data: Dict) → float

Tests the model on dummy data. Images are passed sequentially to make the comparision with OpenVINO model fair.

get_openvino_throughput(config: Union[omegaconf.DictConfig, omegaconf.ListConfig], model_path: pathlib.Path, test_dataset: torch.utils.data.DataLoader, meta_data: Dict) → float

Runs the generated OpenVINO model on a dummy dataset to get throughput.

class anomalib.utils.sweep.helpers.inference.MockImageLoader(image_size: List[int], total_count: int)[source]

Create mock images for inference on CPU based on the specifics of the original torch test dataset.

Uses yield so as to avoid storing everything in the memory.

Parameters
  • image_size (List[int]) – Size of input image

  • total_count (int) – Total images in the test dataset

__len__(self)[source]

Get total count of images.

__call__(self) Iterable[numpy.ndarray][source]

Yield batch of generated images.

Parameters

idx (int) – Unused

anomalib.utils.sweep.helpers.inference.get_meta_data(model: anomalib.models.components.AnomalyModule, input_size: Tuple[int, int]) Dict[source]

Get meta data for inference.

Parameters
  • model (AnomalyModule) – Trained model from which the metadata is extracted.

  • input_size (Tuple[int, int]) – Input size used to resize the pixel level mean and std.

Returns

Metadata as dictionary.

Return type

(Dict)

anomalib.utils.sweep.helpers.inference.get_torch_throughput(config: Union[omegaconf.DictConfig, omegaconf.ListConfig], model: anomalib.models.components.AnomalyModule, test_dataset: torch.utils.data.DataLoader, meta_data: Dict) float[source]

Tests the model on dummy data. Images are passed sequentially to make the comparision with OpenVINO model fair.

Parameters
  • config (Union[DictConfig, ListConfig]) – Model config.

  • model (Path) – Model on which inference is called.

  • test_dataset (DataLoader) – The test dataset used as a reference for the mock dataset.

  • meta_data (Dict) – Metadata used for normalization.

Returns

Inference throughput

Return type

float

anomalib.utils.sweep.helpers.inference.get_openvino_throughput(config: Union[omegaconf.DictConfig, omegaconf.ListConfig], model_path: pathlib.Path, test_dataset: torch.utils.data.DataLoader, meta_data: Dict) float[source]

Runs the generated OpenVINO model on a dummy dataset to get throughput.

Parameters
  • config (Union[DictConfig, ListConfig]) – Model config.

  • model_path (Path) – Path to folder containing the OpenVINO models. It then searches model.xml in the folder.

  • test_dataset (DataLoader) – The test dataset used as a reference for the mock dataset.

  • meta_data (Dict) – Metadata used for normalization.

Returns

Inference throughput

Return type

float