detectionmetrics.models package
Submodules
detectionmetrics.models.model module
- class detectionmetrics.models.model.ImageSegmentationModel(model: Any, model_type: str, model_cfg: str, ontology_fname: str)
Bases:
SegmentationModel
Parent image segmentation model class
- Parameters:
model (Any) – Image segmentation model object
model_type (str) – Model type (e.g. scripted, compiled, etc.)
model_cfg (str) – JSON file containing model configuration (e.g. image size or normalization parameters)
ontology_fname (str) – JSON file containing model output ontology
- abstract eval(dataset: ImageSegmentationDataset, split: str = 'all', ontology_translation: str | None = None) DataFrame
Perform evaluation for an image segmentation dataset
- Parameters:
dataset (ImageSegmentationDataset) – Image segmentation dataset for which the evaluation will be performed
split (str, optional) – Split to be used from the dataset, defaults to “all”
ontology_translation (str, optional) – JSON file containing translation between dataset and model output ontologies
- Returns:
DataFrame containing evaluation results
- Return type:
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
- class detectionmetrics.models.model.LiDARSegmentationModel(model: Any, model_type: str, model_cfg: str, ontology_fname: str)
Bases:
SegmentationModel
Parent LiDAR segmentation model class
- Parameters:
model (Any) – LiDAR segmentation model object
model_type (str) – Model type (e.g. scripted, compiled, etc.)
model_cfg (str) – JSON file containing model configuration (e.g. sampling method, input format, etc.)
ontology_fname (str) – JSON file containing model output ontology
- abstract eval(dataset: LiDARSegmentationDataset, split: str = 'all', ontology_translation: str | None = None) DataFrame
Perform evaluation for a LiDAR segmentation dataset
- Parameters:
dataset (LiDARSegmentationDataset) – LiDAR segmentation dataset for which the evaluation will be performed
split (str, optional) – Split to be used from the dataset, defaults to “all”
ontology_translation (str, optional) – JSON file containing translation between dataset and model output ontologies
- Returns:
DataFrame containing evaluation results
- Return type:
pd.DataFrame
- abstract inference(points: ndarray) ndarray
Perform inference for a single image
- Parameters:
image (np.ndarray) – Point cloud xyz array
- Returns:
Segmenation result as a point cloud with label indices
- Return type:
np.ndarray
- class detectionmetrics.models.model.SegmentationModel(model: Any, model_type: str, model_cfg: str, ontology_fname: str)
Bases:
ABC
Parent segmentation model class
- Parameters:
model (Any) – Segmentation model object
model_type (str) – Model type (e.g. scripted, compiled, etc.)
model_cfg (str) – JSON file containing model configuration
ontology_fname (str) – JSON file containing model output ontology
- abstract eval(dataset: SegmentationDataset, split: str = 'all', ontology_translation: str | None = None) DataFrame
Perform evaluation for an image segmentation dataset
- Parameters:
dataset (ImageSegmentationDataset) – Segmentation dataset for which the evaluation will be performed
split (str, optional) – Split to be used from the dataset, defaults to “all”
ontology_translation (str, optional) – JSON file containing translation between dataset and model output ontologies
- Returns:
DataFrame containing evaluation results
- Return type:
pd.DataFrame
- get_lut_ontology(dataset_ontology: dict, ontology_translation: str | None = None)
Build ontology lookup table (leave empty if ontologies match)
- Parameters:
dataset_ontology (dict) – Image or LiDAR dataset ontology
ontology_translation (Optional[str], optional) – JSON file containing translation between model and dataset ontologies, defaults to None
- abstract inference(points: ndarray | Image) ndarray | Image
Perform inference for a single image or point cloud
- Parameters:
image (Union[np.ndarray, Image.Image]) – Either a numpy array (LiDAR point cloud) or a PIL image
- Returns:
Segmenation result as a point cloud or image with label indices
- Return type:
Union[np.ndarray, Image.Image]
detectionmetrics.models.onnx module
- class detectionmetrics.models.onnx.OnnxImageSegmentationModel(model, model_type, 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 (ImageSegmentationDataset) – Image segmentation dataset for which the evaluation will be performed
split (str, optional) – Split to be used from the dataset, defaults to “all”
ontology_translation (str, optional) – JSON file containing translation between dataset and model output ontologies
- Returns:
DataFrame containing evaluation results
- Return type:
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[tensorflow.Tensor, tensorflow.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) tensorflow.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: str | tensorflow.Module | tensorflow.keras.Model, model_cfg: str, ontology_fname: str)
Bases:
ImageSegmentationModel
Image segmentation model for Tensorflow framework
- Parameters:
model (Union[str, torch.nn.Module]) – Either the filename of a Tensorflow model in SavedModel format or the model already loaded into an arbitrary Tensorflow or Keras model.
model_cfg (str) – JSON file containing model configuration
ontology_fname (str) – JSON file containing model output ontology
- eval(dataset: ImageSegmentationDataset, split: str = 'all', ontology_translation: str | None = None) DataFrame
Perform evaluation for an image segmentation dataset
- Parameters:
dataset (ImageSegmentationDataset) – Image segmentation dataset for which the evaluation will be performed
split (str, optional) – Split to be used from the dataset, defaults to “all”
ontology_translation (str, optional) – JSON file containing translation between dataset and model output ontologies
- Returns:
DataFrame containing evaluation results
- Return type:
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(*args: Any, **kwargs: Any)
Bases:
Dataset
Dataset for image segmentation PyTorch models
- Parameters:
dataset (ImageSegmentationDataset) – Image segmentation dataset
transform (transforms.Compose) – Transformation to be applied to images
target_transform (transforms.Compose) – Transformation to be applied to labels
split (str, optional) – Split to be used from the dataset, defaults to “all”
- class detectionmetrics.models.torch.LiDARSegmentationTorchDataset(*args: Any, **kwargs: Any)
Bases:
Dataset
Dataset for LiDAR segmentation PyTorch models
- Parameters:
dataset (LiDARSegmentationDataset) – LiDAR segmentation dataset
model_cfg (dict) – Dictionary containing model configuration
preprocess (callable) – Function for preprocessing point clouds
n_classes (int) – Number of classes estimated by the model
split (str, optional) – Split to be used from the dataset, defaults to “all”
- class detectionmetrics.models.torch.TorchImageSegmentationModel(model: str | torch.nn.Module, model_cfg: str, ontology_fname: str)
Bases:
ImageSegmentationModel
- eval(dataset: ImageSegmentationDataset, split: str = 'all', ontology_translation: str | None = None) DataFrame
Perform evaluation for an image segmentation dataset
- Parameters:
dataset (ImageSegmentationDataset) – Image segmentation dataset for which the evaluation will be performed
split (str, optional) – Split to be used from the dataset, defaults to “all”
ontology_translation (str, optional) – JSON file containing translation between dataset and model output ontologies
- Returns:
DataFrame containing evaluation results
- Return type:
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
- class detectionmetrics.models.torch.TorchLiDARSegmentationModel(model: str | torch.nn.Module, model_cfg: str, ontology_fname: str)
Bases:
LiDARSegmentationModel
- eval(dataset: LiDARSegmentationDataset, split: str = 'all', ontology_translation: str | None = None) DataFrame
Perform evaluation for a LiDAR segmentation dataset
- Parameters:
dataset (LiDARSegmentationDataset) – LiDAR segmentation dataset for which the evaluation will be performed
split (str, optional) – Split to be used from the dataset, defaults to “all”
ontology_translation (str, optional) – JSON file containing translation between dataset and model output ontologies
- Returns:
DataFrame containing evaluation results
- Return type:
pd.DataFrame
- inference(points: ndarray) ndarray
Perform inference for a single point cloud
- Parameters:
points (np.ndarray) – Point cloud xyz array
- Returns:
Segmenation result as a point cloud with label indices
- Return type:
np.ndarray
- detectionmetrics.models.torch.data_to_device(data: tuple | list, device: torch.device) tuple | list
Move provided data to given device (CPU or GPU)
- Parameters:
data (Union[tuple, list]) – Data provided (it can be a single or multiple tensors)
device (torch.device) – Device to move data to
- Returns:
Data moved to device
- Return type:
Union[tuple, list]
- detectionmetrics.models.torch.unsqueeze_data(data: tuple | list, dim: int = 0) tuple | list
Unsqueeze provided data along given dimension
- Parameters:
data (Union[tuple, list]) – Data provided (it can be a single or multiple tensors)
dim (int, optional) – Dimension that will be unsqueezed, defaults to 0
- Returns:
Unsqueezed data
- Return type:
Union[tuple, list]