geti_sdk.prediction_visualization

Introduction

The prediction_visualization package provides classes for visualizing models predictions and media annotations. Aditionally, shortend interface to this package is available through the plot_helpers module.

The main Visualizer class is a flexible utility class for working with Geti-SDK Prediction and Annotation object. You can initialize the Visualizer with the desired settings and then use it to draw the annotations on the input image.

from geti_sdk import Visualizer

visualizer = Visualizer(
   show_labels=True,
   show_confidence=True,
   show_count=False,
)

# Obtain a prediction from the Intel Geti platfor server or a local deployment.
...

# Visualize the prediction on the input image.
result = visualizer.draw(
   numpy_image,
   prediction,
   fill_shapes=True,
   confidence_threshold=0.4,
)
visualizer.show_in_notebook(result)

In case the Prediction was generated with a model that supports explainable AI functionality, the Visualizer can also display the explanation for the prediction.

Module contents

The package provides the Visualizer class for models predictions visualization.

class geti_sdk.prediction_visualization.visualizer.Visualizer(window_name: str | None = None, show_labels: bool = True, show_confidence: bool = True, show_count: bool = False, is_one_label: bool = False)

Bases: object

Visualize the predicted output by drawing the annotations on the input image.

Example:
>>> prediction = deployment.infer(image)
>>> visualizer = Visualizer()
>>> output_image = visualizer.draw(image, prediction )
>>> Display(output_image)
draw(image: ndarray, annotation: AnnotationScene, fill_shapes: bool = True, confidence_threshold: float | None = None, meta: dict | None = None) ndarray

Draw annotations on the image.

Parameters:
  • image – Input image in RGB format

  • annotation – Annotations to be drawn on the input image

  • meta – Optional meta information

  • fill_shapes – Fill shapes with color

  • confidence_threshold – Confidence threshold to filter annotations. Must be in range [0, 1].

Returns:

Output image with annotations in RGB format

explain_label(image: ndarray, prediction: Prediction, label_name: str, opacity: float = 0.5, show_predictions: bool = True) ndarray

Draw saliency map overlay on the image.

Parameters:
  • image – Input image in RGB format

  • prediction – Prediction object containing saliency maps

  • label_name – Label name to be explained

  • opacity – Opacity of the saliency map overlay

  • show_predictions – Show predictions for the label on the output image

Returns:

Output image with saliency map overlay in RGB format

static save_image(image: ndarray, output_path: PathLike) None

Save the image to the output path.

Parameters:
  • image – Image in RGB format to be saved

  • output_path – Path to save the image

static save_video(video_frames: MediaList[VideoFrame], annotation_scenes: List[AnnotationScene | Prediction], output_path: PathLike, fps: float = 1) None

Save the video to the output path.

Parameters:
  • video_frames – List of video frames

  • annotation_scenes – List of annotation scenes to be drawn on the video frames

  • output_path – Path to save the image

static show_in_notebook(image: ndarray) None

Show the image in the Jupyter notebook.

Parameters:

image – Image to be shown in RGB format

show_window(image: ndarray) None

Show result image.

Parameters:

image – Image to be shown (in RGB order).

is_quit(delay: int = 1) bool

Check user wish to quit.

class geti_sdk.prediction_visualization.shape_drawer.ShapeDrawer(show_count: bool, is_one_label: bool, show_labels: bool, show_confidence: bool)

Bases: DrawerEntity[AnnotationScene]

ShapeDrawer to draw any shape on a numpy array. Will overlay the shapes in the same way that the UI does.

Parameters:
  • show_count – Whether or not to render the amount of objects on screen in the top left.

  • is_one_label – Whether there is only one label present in the project.

draw(image: ndarray, scene: AnnotationScene | Prediction, labels: List[ScoredLabel], fill_shapes: bool = True) ndarray

Use a compatible drawer to draw all shapes of an annotation to the corresponding image.

Also render a label in the top left if we need to.

Parameters:
  • image – Numpy image, one frame of a video on which to draw

  • scene – AnnotationScene scene corresponding to this particular frame of the video

  • labels – Can be passed as an empty list since they are already present in annotation_scene

Returns:

Modified image.

class TopLeftDrawer(show_labels, show_confidence, is_one_label)

Bases: Helpers, DrawerEntity[Annotation]

Draws labels in an image’s top left corner.

draw(image: ndarray, annotation: Annotation, labels: List[ScoredLabel]) ndarray

Draw the labels of a shape in the image top left corner.

Parameters:
  • image – Image

  • annotation – Annotation

  • labels – (Unused) labels to be drawn on the image

Returns:

Image with label on top.

draw_labels(image: ndarray, labels: Sequence[Label | ScoredLabel]) ndarray

Draw the labels in the image top left corner.

Parameters:
  • image – Image

  • labels – Sequence of labels

Returns:

Image with label on top.

draw_annotation_count(image: ndarray, num_annotations: int) ndarray

Draw the number of annotations to the top left corner of the image.

Parameters:
  • image – Image

  • num_annotations – Number of annotations

Returns:

Image with annotation count on top.

class RectangleDrawer(show_labels, show_confidence)

Bases: Helpers, DrawerEntity[Rectangle]

Draws rectangles.

supported_types: Sequence[Type[Shape]] = [<class 'geti_sdk.data_models.shapes.Rectangle'>]
draw(image: ndarray, entity: Rectangle, labels: List[ScoredLabel], fill_shapes: bool = True) ndarray

Draw a rectangle on the image along with labels.

Parameters:
  • image – Image to draw on.

  • entity – Rectangle to draw.

  • labels – List of labels.

  • fill_shapes – Whether to fill the shapes with color.

Returns:

Image with rectangle drawn on it.

class EllipseDrawer(show_labels, show_confidence)

Bases: Helpers, DrawerEntity[Ellipse]

Draws ellipses.

supported_types: Sequence[Type[Shape]] = [<class 'geti_sdk.data_models.shapes.Ellipse'>]
draw(image: ndarray, entity: Ellipse, labels: List[ScoredLabel], fill_shapes: bool = True) ndarray

Draw the ellipse on the image.

Parameters:
  • image – Image to draw on.

  • entity – Ellipse to draw.

  • labels – Labels to draw.

  • fill_shapes – Whether to fill the shapes with color.

Returns:

Image with the ellipse drawn on it.

class PolygonDrawer(show_labels, show_confidence)

Bases: Helpers, DrawerEntity[Polygon]

Draws polygons.

supported_types: Sequence[Type[Shape]] = [<class 'geti_sdk.data_models.shapes.Polygon'>, <class 'geti_sdk.data_models.shapes.RotatedRectangle'>]
draw(image: ndarray, entity: Polygon | RotatedRectangle, labels: List[ScoredLabel], fill_shapes: bool = True) ndarray

Draw polygon and labels on image.

Parameters:
  • image – Image to draw on.

  • entity – Polygon to draw.

  • labels – List of labels to draw.

  • fill_shapes – Whether to fill the shapes with color.

Returns:

Image with polygon drawn on it.