ParticleDetection.modelling.visualization

Functions to visualize predictions of Detectron2 models.

Author: Adrian Niemann (adrian.niemann@ovgu.de)

Date: 11.08.2022

create_figure(img, predictions, gt: dict | None = None, colors: Iterable | None = None)[source]

Plots an image with the predictions from a model overlayed.

Can plot either just the image with the given predictions, e.g. segmentation masks, or together with the ground-truth data. The latter produces a figure of vertically two stacked images, where the lower one shows the ground-truth data.

Parameters:
  • img (ndarray) – Loaded image file with dimensions [h, w, c].

  • predictions – Predictions of a one image, for details see the Detectron2 documentation.

  • gt (dict, optional) –

    A full ground-truth dataset entry with all metadata, e.g. keypoints.

    By default None.

  • colors (Iterable, optional) –

    Specifies the color used during plotting for each class that is predictable by the model. The colors of the “tab10” colormap will be used by default.

    By default None.

Returns:

Figure

visualize(prediction, original: dict | str | ndarray, hide_tags=True, output_dir='', colors: Iterable | None = None, **_)[source]

Visualizes predictions on one image with/without it’s ground truth.

Parameters:
  • prediction – Predictions of a one image, for details see the Detectron2 documentation.

  • original (Union[dict, str, ndarray]) –

    Is either the full dataset entry with all metadata, just the path to the image file used during inference or the loaded image itself.

    dict —> full dataset entry

    str —> path to image

    ndarray —> image in BGR format

  • hide_tags (bool, optional) –

    Flag to remove the "scores" field, such that it is not visualized.

    By default True.

  • output_dir (str, optional) –

    Path to the intended output directory. This directory must exist prior to running this function.

    By default "".

  • colors (Iterable, optional) –

    Specifies the color used during plotting for each class that is predictable by the model. The colors of the "tab10" colormap will be used by default.

    By default None.