detectionmetrics.models package

Submodules

detectionmetrics.models.model module

class detectionmetrics.models.model.ImageSegmentationModel(ontology_fname: str, model_cfg: str)

Bases: ABC

Parent image segmentation model class

Parameters:
  • ontology_fname (str) – JSON file containing model output ontology

  • model_cfg – JSON file containing model configuration (e.g. image size or

normalization parameters) :type model_cfg: str

abstract eval(dataset: ImageSegmentationDataset, batch_size: int = 1, split: str = 'all', ontology_translation: str | None = None) DataFrame

Perform evaluation for an image segmentation dataset

Parameters:

dataset_test – Image segmentation dataset for which the evaluation will

be performed :type dataset_test: ImageSegmentationDataset :param batch_size: Batch size, defaults to 1 :type batch_size: int, optional :param split: Split to be used from the dataset, defaults to “all” :type split: str, optional :param ontology_translation: JSON file containing translation between dataset and model output ontologies :type ontology_translation: str, optional :return: DataFrame containing evaluation results :rtype: pd.DataFrame

abstract inference(image: Image) Image

Perform inference for a single image

Parameters:

image (Image.Image) – PIL image.

Returns:

segmenation result as PIL image

Return type:

Image.Image

detectionmetrics.models.onnx module

class detectionmetrics.models.onnx.OnnxImageSegmentationModel(ontology_fname, model_cfg)

Bases: ImageSegmentationModel

eval(dataset, batch_size=1, split='all', ontology_translation=None)

Perform evaluation for an image segmentation dataset

Parameters:

dataset_test – Image segmentation dataset for which the evaluation will

be performed :type dataset_test: ImageSegmentationDataset :param batch_size: Batch size, defaults to 1 :type batch_size: int, optional :param split: Split to be used from the dataset, defaults to “all” :type split: str, optional :param ontology_translation: JSON file containing translation between dataset and model output ontologies :type ontology_translation: str, optional :return: DataFrame containing evaluation results :rtype: pd.DataFrame

inference(image)

Perform inference for a single image

Parameters:

image (Image.Image) – PIL image.

Returns:

segmenation result as PIL image

Return type:

Image.Image

detectionmetrics.models.tensorflow module

class detectionmetrics.models.tensorflow.ImageSegmentationTensorflowDataset(dataset: ImageSegmentationDataset, image_size: Tuple[int, int], batch_size: int = 1, split: str = 'all', lut_ontology: dict | None = None)

Bases: object

Dataset for image segmentation Tensorflow models

Parameters:
  • dataset (ImageSegmentationDataset) – Image segmentation dataset

  • image_size (Tuple[int, int]) – Image size in pixels (width, height)

  • batch_size (int, optional) – Batch size, defaults to 1

  • split (str, optional) – Split to be used from the dataset, defaults to “all”

  • lut_ontology (dict, optional) – LUT to transform label classes, defaults to None

load_data(images_fnames: List[str], labels_fnames: List[str]) Tuple[Tensor, Tensor]

Function for loading data for each dataset sample

Parameters:
  • images_fnames (List[str]) – List containing all image filenames

  • labels_fnames (List[str]) – List containing all corresponding label filenames

Returns:

Image and label tensor pairs

Return type:

Tuple[tf.Tensor, tf.Tensor]

read_image(fname: str, label=False) Tensor

Read a single image or label

Parameters:
  • fname (str) – Input image or label filename

  • label (bool, optional) – Whether the input data is a label or not, defaults to False

Returns:

Tensorflow tensor containing read image or label

Return type:

tf.Tensor

class detectionmetrics.models.tensorflow.TensorflowImageSegmentationModel(model_fname: str, model_cfg: str, ontology_fname: str)

Bases: ImageSegmentationModel

Image segmentation model for Tensorflow framework

Parameters:
  • model_fname (str) – Tensorflow model in SavedModel format

  • model_cfg (str) – JSON file containing model configuration

  • ontology_fname (str) – JSON file containing model output ontology

eval(dataset: ImageSegmentationDataset, batch_size: int = 1, split: str = 'all', ontology_translation: str | None = None) DataFrame

Perform evaluation for an image segmentation dataset

Parameters:

dataset_test – Image segmentation dataset for which the evaluation will

be performed :type dataset_test: ImageSegmentationDataset :param batch_size: Batch size, defaults to 1 :type batch_size: int, optional :param split: Split to be used from the dataset, defaults to “all” :type split: str, optional :param ontology_translation: JSON file containing translation between dataset and model output ontologies :type ontology_translation: str, optional :return: DataFrame containing evaluation results :rtype: pd.DataFrame

inference(image: Image) Image

Perform inference for a single image

Parameters:

image (Image.Image) – PIL image

Returns:

segmenation result as PIL image

Return type:

Image.Image

detectionmetrics.models.torch module

class detectionmetrics.models.torch.ImageSegmentationTorchDataset(dataset: ImageSegmentationDataset, transform: Compose, target_transform: Compose, split: str = 'all')

Bases: Dataset

Dataset for image segmentation PyTorch models

Parameters:
  • dataset (ImageSegmentationDataset) – Image segmentation dataset

  • transform (v2.Compose) – Transformation to be applied to images

  • target_transform (v2.Compose) – Transformation to be applied to labels

  • split (str, optional) – Split to be used from the dataset, defaults to “all”

class detectionmetrics.models.torch.TorchImageSegmentationModel(model_fname: str, model_cfg: str, ontology_fname: str)

Bases: ImageSegmentationModel

eval(dataset: ImageSegmentationDataset, batch_size: int = 1, split: str = 'all', ontology_translation: str | None = None) DataFrame

Perform evaluation for an image segmentation dataset

Parameters:

dataset_test – Image segmentation dataset for which the evaluation will

be performed :type dataset_test: ImageSegmentationDataset :param batch_size: Batch size, defaults to 1 :type batch_size: int, optional :param split: Split to be used from the dataset, defaults to “all” :type split: str, optional :param ontology_translation: JSON file containing translation between dataset and model output ontologies :type ontology_translation: str, optional :return: DataFrame containing evaluation results :rtype: pd.DataFrame

inference(image: Image) Image

Perform inference for a single image

Parameters:

image (Image.Image) – PIL image

Returns:

segmenation result as PIL image

Return type:

Image.Image

Module contents