SDK reference

mp_sdk.training.AnnotatedImage

 class mp_sdk.training.AnnotatedImage(*args,
     id: int = None,
     source_image_id: int,
     url: str,
     name: str,
     path: str,
     width: int,
     height: int,
     annotations: List[mp_sdk.training.models.ImageAnnotation],
     annotation_labels: List[mp_sdk.training.models.AnnotationLabel],
     layers: List[mp_sdk.training.models.ImageLayer],
     classification: int = None
)

Annotated image object.

Represents an image with corresponding annotations.

Attributes

  • id - int: The image ID.

  • path - str: Path to the image file in local file system.

  • url - str: The image URL.

  • pil_image - PILImage: The PIL image object.

  • width - int: The image width in pixels.

  • height - int: The image height in pixels.

  • annotations - List[ImageAnnotation]: List of annotations provided by the application user.

  • classification - int: Classification label for the image if engine is type of image classification.

  • annotation_labels - List[AnnotationLabel]: List of annotation labels referenced by label attribute of mp_sdk.training.ImageAnnotation objects.

  • layers - List[ImageLayer]: List of image layers that can be stacked with the image.

Methods

__init__

(self, *args, **kwargs)

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

__init__ uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

copy_with

(self, update: dict)

get_layers_paths

(self) -> List[str]

Returns a list of paths to image layers including cover image.

This method can be used if custom stacking or processing of image layers is required (for example, is resizing is required before stacking).

Returns

  • List[str] - List of paths to image layers.

save

(self, folder_path: str, override: bool = False) -> str

Saves the image to a file.

Image will be saved to folder_path with current name self.name. After saving will update self.path with the full path to the saved file.

Arguments

  • folder_path: str - The path to the folder where to save the image.

  • override: bool (optional) - If set to True, will override existing file with same path. Defaults to False.

Returns

  • str - Full path to the saved file.

Raises

  • ValueError - If override is set to False and file already exists.

save_annotations

(self, format: Literal['yolov5', 'voc_xml'], folder: str = None) -> str

Saves annotations to a file.

Annotations will be saved to folder with provided format and name composed from image name and corresponding to format suffix.

Arguments

  • format: str - The format of the annotations. Supported formats: "yolov5".

  • folder: str (optional) - The path to the folder where to save the annotations. If not is not provided, will save annotation to the same folder as the image with the same name and corresponding to format extension.

Returns

  • str - Full path to the saved file.

Raises

  • ValueError - If format is not supported.

save_stacked

(self, folder_path: str, override: bool = False) -> str

Converts image layers to arrays and stacks them into a single TIFF file before saving a file.

Image layers will be saved to folder_path with current name self.name with .tiff suffix. It uses NumPy's dstack method to stack image layers into a single array. After saving will update self.path with the full path to the saved file.

Arguments

  • folder_path: str - The path to the folder where to save the image.

  • override: bool (optional) - If set to True, will override existing file with same path. Defaults to False.

Returns

  • str - Full path to the saved file.

Raises

  • ValueError - If override is set to False and file already exists.

  • ValueError - If images have different dimensions.

sync

(self, client: mp_sdk.api.rest.ApiClient = None, is_validation: bool = False)

Syncs the image with application storage.

This method is used to sync images with application storage after they have been preprocessed. It will upload the image to application storage and link processed image with the source image. Will update self.id with the ID of the synced image.

Arguments

  • client: ApiClient - The API client object. If not provided will use default client.
Previous
Inference engine