geti_sdk.utils

Introduction

The utils package contains utility functions used throughout the SDK.

Module contents

geti_sdk.utils.get_default_workspace_id(rest_session: GetiSession) str

Return the id of the default workspace on the cluster.

Parameters:

rest_session – HTTP session to the cluser

Returns:

string containing the id of the default workspace

geti_sdk.utils.generate_classification_labels(labels: List[str], multilabel: bool = False) List[Dict[str, str]]

Generate label creation data from a list of label names. If multiclass = True, the labels will be generated in such a way that multiple labels can be assigned to a single image. If multiclass = False, only a single label per image can be assigned.

Parameters:
  • labels – Label names to be used

  • multilabel – True to be able to assign multiple labels to one image, False otherwise. Defaults to False.

Returns:

List of dictionaries containing the label data that can be sent to the Intel® Geti™ project creation endpoint

geti_sdk.utils.generate_segmentation_labels(detection_labels: List[str]) List[str]

Generate segmentation label names from a list of detection label names.

Parameters:

detection_labels – label names to generate segmentation label names for

Returns:

List of label names

geti_sdk.utils.get_dict_key_from_value(input_dict: Dict[KeyType, Any], value) KeyType | None

Return the key associated with value in a dictionary input_dict. If the value is not found in the dictionary, returns None.

Parameters:
  • input_dict – Dictionary to search in

  • value – value to search for

Returns:

key associated with value if value is in the input_dict, None otherwise

geti_sdk.utils.get_task_types_by_project_type(project_type: str) List[TaskType]

Return a list of task_type for each task in the project pipeline, for a certain ‘project_type’.

Parameters:

project_type

Returns:

geti_sdk.utils.show_image_with_annotation_scene(image: Image | VideoFrame | ndarray, annotation_scene: AnnotationScene | Prediction, filepath: str | None = None, show_in_notebook: bool = False, show_results: bool = True, channel_order: str = 'rgb', show_labels: bool = True, show_confidences: bool = True, fill_shapes: bool = True) ndarray

Display an image with an annotation_scene overlayed on top of it.

Parameters:
  • image – Image to show prediction for.

  • annotation_scene – Annotations or Predictions to overlay on the image

  • filepath – Optional filepath to save the image with annotation overlay to. If left as None, the result will not be saved to file

  • show_in_notebook – True if the image needs to be shown in a notebook context. Setting this to True will display the image inline in the notebook. Setting it to False will open a pop up to show the image.

  • show_results – True to show the results. If show_in_notebook is True, this will display the image with the annotations inside the notebook. If show_in_notebook is False, a new opencv window will pop up. If show_results is set to False, the results will not be shown but will only be returned instead

  • channel_order – The channel order (R,G,B or B,G,R) used for the input image. This parameter accepts either rgb or bgr as input values, and defaults to rgb.

  • show_labels – True to show the labels of the annotations. If set to False, the labels will not be shown.

  • show_confidences – True to show the confidences of the annotations. If set to False, the confidences will not be shown.

  • fill_shapes – True to fill the shapes of the annotations. If set to False, the shapes will not be filled.

geti_sdk.utils.show_video_frames_with_annotation_scenes(video_frames: MediaList[VideoFrame], annotation_scenes: List[AnnotationScene | Prediction], wait_time: float = 1, filepath: str | None = None, show_labels: bool = True, show_confidences: bool = True, fill_shapes: bool = True)

Display a list of VideoFrames, with their annotations or predictions overlayed on top. The parameter wait_time specifies the time each frame is shown, in seconds.

Parameters:
  • video_frames – List of VideoFrames to show

  • annotation_scenes – List of AnnotationsScenes or Predictions to overlay on the frames

  • wait_time – Time to show each frame, in seconds

  • filepath – Optional filepath to save the video with annotation overlay to. If left as None, the video frames will be shown in a new opencv window

  • show_labels – True to show the labels of the annotations. If set to False, the labels will not be shown.

  • show_confidences – True to show the confidences of the annotations. If set to False, the confidences will not be shown.

  • fill_shapes – True to fill the shapes of the annotations. If set to False, the shapes will not be filled.

geti_sdk.utils.get_supported_algorithms(rest_session: GetiSession, task_type: TaskType | None = None, project: Project | None = None, workspace_id: str | None = None) AlgorithmList

Return the list of supported algorithms (including algorithm metadata) for the cluster.

Parameters:
  • rest_session – HTTP session to the cluster

  • task_type – Optional TaskType for which to get the supported algorithms.

  • project – Project to get the supported algorithms for. NOTE: project is not required for Geti versions v1.8 and lower, but is mandatory for v1.9 and up.

  • workspace_id – ID of the workspace in which the project to get the supported algorithms for lives. NOTE: This is not required for Geti versions v1.8 and lower, but is mandatory for v1.9 and up.

Returns:

AlgorithmList holding the supported algorithms

geti_sdk.utils.deserialize_dictionary(input_dictionary: Dict[str, Any], output_type: Type[OutputTypeVar]) OutputTypeVar

Deserialize an input_dictionary to an object of the type passed in output_type.

Parameters:
  • input_dictionary – Dictionary to deserialize

  • output_type – Type of the object that the dictionary represents, and to which the data will be deserialized

Returns:

Object of type output_type, holding the data passed in input_dictionary.

geti_sdk.utils.get_server_details_from_env(env_file_path: str = '.env', use_global_variables: bool = False) ServerTokenConfig | ServerCredentialConfig

Retrieve the server information (hostname and authentication details) from environment variables.

By default, this method will attempt to find a file “.env” in the current working directory and attempt to read the information from that file. To read from a different file, simply specify the path to the file in env_file_path. The following variables are relevant:

HOST -> hostname or ip address of the Geti server

TOKEN -> Personal Access Token that can be used for authorization

VERIFY_CERT -> boolean, pass 1 or True to verify

HTTPS_PROXY -> Address of the proxy to be used for https communication. Make

sure to specify the full address, including port number. For example: HTTPS_PROXY=http://proxy.my-company.com:900

In addition, authentication via credentials is also supported. In that case, the following variables should be provided:

USERNAME -> username to log in to the Geti server

PASSWORD -> password for logging in to the Geti server

If both TOKEN, USERNAME and PASSWORD are provided, the method will use the preferred token authorization.

If use_global_variables is set to True, the method attempts to retrieve the server details from the global environment variables instead of reading from file. In that case, the GETI_ prefix should be added to the variable names (i.e. HOST becomes GETI_HOST, TOKEN becomes GETI_TOKEN, etc.)

Parameters:
  • env_file_path – Path to the file containing the server details

  • use_global_variables – If set to True, the method will not read the server details from a file but will use environment variables instead

Returns:

A ServerConfig instance that contains the details of the Geti server specified in the environment

geti_sdk.utils.get_project_folder_name(project: Project) str

Return a folder name for the project, that can be used to download the project to.

Parameters:

project – Project to get a folder name for

Returns:

string holding the folder name for the project

geti_sdk.utils.generate_unique_label_color(label_colors: Sequence[str]) str

Generate a label color that is unique from the label colors used in labels.

Parameters:

label_colors – List of hex color strings with respect to which the new color should be generated

Returns:

hex string containing the new label color

geti_sdk.utils.get_default_algorithm_info(session: GetiSession, workspace_id: str, project: Project) Dict[TaskType, str]

Return the names of the default algorithms for the tasks in the project. The returned response is a map of TaskType to the default algorithm name for that task

Parameters:
  • session – GetiSession to the Intel Geti server

  • workspace_id – Workspace ID in which the project to retrieve the default algorithms for lives.

  • project – Project to retrieve the default algorithms for

Returns:

Dictionary mapping the default algorithm name to the TaskType, for each task in the project