geti_sdk.demos

Introduction

The demos package contains useful functions for setting up demo projects on any Intel® Geti™ server.

Module contents

geti_sdk.demos.create_segmentation_demo_project(geti: Geti, n_images: int, n_annotations: int = -1, auto_train: bool = False, dataset_path: str | None = None, project_name: str = 'Segmentation demo') Project

Create a demo project of type ‘segmentation’, based off the MS COCO dataset.

This method creates a project with a single ‘Segmentation’ task, with segmentation mask for labels: ‘backpack’ and ‘suitcase’.

Parameters:
  • geti – Geti instance, representing the GETi server on which the project should be created.

  • n_images – Number of images that should be uploaded. Pass -1 to upload all available images in the dataset for the given labels

  • n_annotations – Number of images that should be annotated. Pass -1 to upload annotations for all images.

  • auto_train – True to set auto-training to True once the project has been created and the images have been annotated, False to leave auto-training turned off.

  • dataset_path – Path to the COCO dataset to use as data source. Defaults to the ‘data’ directory in the top level folder of the geti_sdk package. If the dataset is not found in the target folder, this method will attempt to download it from the internet.

  • project_name – Name of the project to create

Returns:

Project object, holding detailed information about the project that was created on the Intel® Geti™ server.

geti_sdk.demos.create_anomaly_classification_demo_project(geti: Geti, n_images: int, n_annotations: int = -1, project_name: str = 'Anomaly demo', dataset_path: str | None = None) Project

Create a demo project of type ‘anomaly’, based off the MVTec anomaly detection dataset.

This method creates a project with a single ‘Anomaly’ task.

Parameters:
  • geti – Geti instance, representing the GETi server on which the project should be created.

  • n_images – Number of images that should be uploaded. Pass -1 to upload all available images in the dataset for the given labels

  • n_annotations – Number of images that should be annotated. Pass -1 to upload annotations for all images.

  • project_name – Name of the project to create. Defaults to ‘Anomaly demo’

  • dataset_path – Path to the dataset to use as data source. Defaults to the ‘data’ directory in the top level folder of the geti_sdk package. If the dataset is not found in the target folder, this method will attempt to download it from the internet.

Returns:

Project object, holding detailed information about the project that was created on the Intel® Geti™ server.

geti_sdk.demos.create_classification_demo_project(geti: Geti, n_images: int, n_annotations: int = -1, auto_train: bool = False, dataset_path: str | None = None, project_name: str = 'Classification demo') Project

Create a demo project of type ‘classification’, based off the MS COCO dataset.

This method creates a project with a single ‘Classification’ task, with labels to classify images with different types of animals. The following animals are considered: “horse”, “cat”, “zebra”, “bear”

Parameters:
  • geti – Geti instance, representing the GETi server on which the project should be created.

  • n_images – Number of images that should be uploaded. Pass -1 to upload all available images in the dataset for the given labels

  • n_annotations – Number of images that should be annotated. Pass -1 to upload annotations for all images.

  • auto_train – True to set auto-training to True once the project has been created and the images have been annotated, False to leave auto-training turned off.

  • dataset_path – Path to the COCO dataset to use as data source. Defaults to the ‘data’ directory in the top level folder of the geti_sdk package. If the dataset is not found in the target folder, this method will attempt to download it from the internet.

  • project_name – Name of the project to create

Returns:

Project object, holding detailed information about the project that was created on the Intel® Geti™ server.

geti_sdk.demos.create_detection_demo_project(geti: Geti, n_images: int, n_annotations: int = -1, auto_train: bool = False, dataset_path: str | None = None, project_name: str = 'Detection demo') Project

Create a demo project of type ‘detection’, based off the MS COCO dataset.

This method creates a project with a single ‘Detection’ task, with labels and annotations for ‘cell phone’ and ‘person’ objects

Parameters:
  • geti – Geti instance, representing the GETi server on which the project should be created.

  • n_images – Number of images that should be uploaded. Pass -1 to upload all available images in the dataset for the given labels

  • n_annotations – Number of images that should be annotated. Pass -1 to upload annotations for all images.

  • auto_train – True to set auto-training to True once the project has been created and the images have been annotated, False to leave auto-training turned off.

  • dataset_path – Path to the COCO dataset to use as data source. Defaults to the ‘data’ directory in the top level folder of the geti_sdk package. If the dataset is not found in the target folder, this method will attempt to download it from the internet.

  • project_name – Name of the project to create

Returns:

Project object, holding detailed information about the project that was created on the Intel® Geti™ server.

geti_sdk.demos.create_detection_to_segmentation_demo_project(geti: Geti, n_images: int, n_annotations: int = -1, auto_train: bool = False, dataset_path: str | None = None, project_name: str = 'Animal detection to segmentation demo') Project

Create a demo project of type ‘detection_to_segmentation’, based off the MS COCO dataset.

This method creates a project with a ‘Detection’ task, followed by a ‘Segmentation’ task. The detection task has the label ‘animal’, and the segmentation task has annotations for the following species:

“dog”, “cat”, “horse”, “elephant”, “cow”, “sheep”, “giraffe”, “zebra”, “bear”

Parameters:
  • geti – Geti instance, representing the GETi server on which the project should be created.

  • n_images – Number of images that should be uploaded. Pass -1 to upload all available images in the dataset for the given labels

  • n_annotations – Number of images that should be annotated. Pass -1 to upload annotations for all images.

  • auto_train – True to set auto-training to True once the project has been created and the images have been annotated, False to leave auto-training turned off.

  • dataset_path – Path to the COCO dataset to use as data source. Defaults to the ‘data’ directory in the top level folder of the geti_sdk package. If the dataset is not found in the target folder, this method will attempt to download it from the internet.

  • project_name – Name of the project to create

Returns:

Project object, holding detailed information about the project that was created on the Intel® Geti™ server.

geti_sdk.demos.create_detection_to_classification_demo_project(geti: Geti, n_images: int, n_annotations: int = -1, auto_train: bool = False, dataset_path: str | None = None, project_name: str = 'Animal detection to classification demo') Project

Create a demo project of type ‘detection_to_classification’, based off the MS COCO dataset.

This method creates a project with a ‘Detection’ task, followed by a ‘Classification’ task. The detection task has the label ‘animal’, and the classification task discriminates between ‘domestic’ and ‘wild’ animals.

Parameters:
  • geti – Geti instance, representing the GETi server on which the project should be created.

  • n_images – Number of images that should be uploaded. Pass -1 to upload all available images in the dataset for the given labels

  • n_annotations – Number of images that should be annotated. Pass -1 to upload annotations for all images.

  • auto_train – True to set auto-training to True once the project has been created and the images have been annotated, False to leave auto-training turned off.

  • dataset_path – Path to the COCO dataset to use as data source. Defaults to the ‘data’ directory in the top level folder of the geti_sdk package. If the dataset is not found in the target folder, this method will attempt to download it from the internet.

  • project_name – Name of the project to create

Returns:

Project object, holding detailed information about the project that was created on the Intel® Geti™ server.

geti_sdk.demos.ensure_trained_example_project(geti: Geti, project_name: str = 'COCO dog detection') Project

Ensure that the project specified by project_name exists on the GETi instance addressed by geti.

Parameters:
  • geti – Geti instance pointing to the GETi server

  • project_name – Name of the project

Returns:

Project object, representing the project in GETi

geti_sdk.demos.ensure_trained_anomaly_project(geti: Geti, project_name: str = 'Transistor anomaly detection')

Check whether the project named project_name exists on the server, and create it if it not.

If the project does not exist, this method will create an anomaly detection project based on the MVTec AD transistor dataset.

Parameters:
  • geti – Geti instance pointing to the Intel® Geti™ server

  • project_name – Name of the project to look for or create

Returns:

Project object representing the project on the server

geti_sdk.demos.ensure_project_is_trained(geti: Geti, project: Project) bool

Ensure that the project has a trained model for each task.

If no trained model is found for any of the tasks, the function will attempt to start training for that task. It will then await the completion of the training job.

This method returns True if all tasks in the project have a trained model available, and the project is therefore ready to make predictions.

Parameters:
  • geti – Geti instance pointing to the GETi server

  • project – Project object, representing the project in GETi

Returns:

True if the project is trained and ready to make predictions, False otherwise

geti_sdk.demos.get_coco_dataset(dataset_path: str | None = None, verbose: bool = False) str

Check if the COCO dataset is present at the specified path. If not, this method will attempt to download the dataset to the path specified.

If no path is passed, this method will check or create the default path: the folder ‘data’ in the top level of the geti-sdk package.

Parameters:
  • dataset_path – Path to check against.

  • verbose – True to print detailed output, False to check silently

Returns:

Path to the COCO dataset

geti_sdk.demos.get_mvtec_dataset(dataset_path: str | None = None) str

Check if the MVTEC ‘transistor’ dataset is present at the specified path. If not, this method will attempt to download the dataset to the path specified.

If no path is passed, this method will check or create the default path: the folder ‘data’ in the top level of the geti-sdk package.

Parameters:
  • dataset_path – Path to check against.

  • verbose – True to print detailed output, False to check silently

Returns:

Path to the COCO dataset

geti_sdk.demos.set_directory_permissions(target_directory: str, file_permissions=432, dir_permissions=504) None

Set read, write, execute permissions for user and user_group on a directory tree.

NOTE: Please use this method with caution, on temporary directories only

Parameters:
  • target_directory – path to the directory for which to set the permissions

  • file_permissions – Permissions to apply to all files found in the directory tree

  • dir_permissions – Permissions to apply to all directories found in the directory tree

geti_sdk.demos.get_person_car_bike_video(video_path: str | PathLike | None = None) str

Get the path to the ‘person-bicycle-car-detection.mp4’ video file that is used for the notebook demos in the Geti SDK

Parameters:

video_path – Optional file path to video. Only specify this if you have already downloaded the video to a different path than the default data path in the SDK.

Returns:

Path to the video

geti_sdk.demos.predict_video_from_deployment(video_path: str | PathLike, deployment: Deployment | str | PathLike, device: str = 'CPU', preserve_audio: bool | None = True) str | None

Create a video reconstruction with overlaid model predictions. This function runs inference on the local machine for every frame in the video. The inference results are overlaid on the frames and the output video path will be returned.

Parameters:
  • video_path – File path to video

  • deployment – Path to the folder containing the Deployment data, or Deployment instance

  • device – Device (CPU or GPU) to load the model to. Defaults to ‘CPU’

  • preserve_audio – True to preserve all audio in the original input video. Defaults to True. If ffmpeg could not be found, this option is ignored and no audio would be preserved.

Returns:

The file path of the output video if generated successfully. Otherwise None.

class geti_sdk.demos.AsyncVideoProcessor(deployment: Deployment, processing_function: Callable[[ndarray, Prediction, Any], None], min_buffer_size: int | None = None, max_buffer_size: int | None = None)

Bases: object

A helper class for efficient and optimized frame-by-frame inference on videos

start(num_frames: int | None = None)

Start the processing thread.

Parameters:

num_frames – Optional integer specifying the length of the video to process. When processing a continuous stream, leave this as None

stop()

Stop the processing thread immediately. Any items left in the buffer will not be processed.

process(frame: ndarray, runtime_data: Any | None = None)

Run inference for the frame and process the results according to the processing_function defined in the AsyncVideoProcessor initialization.

Parameters:
  • frame – Numpy array representing the frame, in RGB-channel order

  • runtime_data – Additional optional data pertaining to the frame, which should be passed to the processing_function

await_all()

Block program execution until all frames left in the buffer have been fully processed.