thelper.gui package

Graphical User Interface (GUI) package.

This package contains various tools and annotators used to simplify user interactions with data or models. Since the training framework is CLI-based, these tools are not used to train models, but can be helpful when debugging them. They can also be used to annotate and explore datasets.

Submodules

thelper.gui.annotators module

Graphical User Interface (GUI) annotator module.

This module contains various annotators that define interactive ways to visualize and annotate data loaded via a dataset parser.

class thelper.gui.annotators.Annotator(session_name, config, save_dir, datasets)[source]

Bases: object

Abstract annotation tool used to define common functions for all GUI-based I/O.

Example configuration file:

# ...
"annotator": {
    # type of annotator to instantiate
    "type": "thelper.gui.ImageSegmentAnnotator",
    # ...
    # provide all extra parameters to the specialized anntator here
    "params": {
        # ...
    }
},
# ...
__init__(session_name, config, save_dir, datasets)[source]

Receives the annotator configuration dictionary, parses it, and sets up the basic session attributes.

run()[source]

Displays the GUI tool and blocks until it it closed by the user.

class thelper.gui.annotators.ImageSegmentAnnotator(session_name, config, save_dir, datasets)[source]

Bases: thelper.gui.annotators.Annotator

Annotator interface specialized for image segmentation annotation generation.

This interface will create a GUI tool with a brush and a zoomed tooltip window that allows images to be painted over with predetermined class labels. The generated masks will then be saved in the session directory as PNG images.

The configuration is expected to provide values for at least the following parameters:

  • sample_input_key: specifies the key to use when extracting images from loaded samples. This is typically a string defined by the dataset parser.
  • labels: provides a list of labels that will be available to use in the GUI. These labels are expected to be given as dictionaries that each define an id (uint8 value used in output masks), a name (string used for display/lookup purposes), and a color (3-element integer tuple).

Other parameters can also be provided to alter the GUI’s default behavior:

  • default_brush_radius: the size of the brush at startup (default=10).
  • background_id: the integer id to use for the background label (default=0).
  • window_zoom_crop_size: the crop size displayed in the zoom tooltip (default=250x250).
  • window_zoom_size: the size of the zoom tooltip window (default=500x500).
  • zoom_interp_type: the interpolation type to use when zooming (default=cv2.INTER_NEAREST).
  • start_sample_idx: the index of the first sample to display (default=0).
  • window_name: the name of the main display window (default=image-segm-annotator).
  • window_size: the size of the main display window (default=1000).
  • brush_thickness: the size of the GUI brush tooltip border display (default=2).
  • gui_bar_size: the width of the GUI bar displayed on top of the main window (default=50).
  • default_mask_opacity: the default opacity of the segmentation mask (default=0.3).
  • default_fill_id: the label id to fill all new masks with (default=0).
BRUSH_SIZE = None
class Brush(config)[source]

Bases: object

Brush manager used to refresh/draw mask contents based on mouse input.

__init__(config)[source]

Parses the input config and extracts brush-related parameters.

static draw_stroke(mask, label_id, start, end)[source]

Draws a brush stroke on the mask with a given label id between two points.

refresh(mask, label)[source]

Fetches the latest mouse state and updates the mask if necessary.

CURRENT_KEY = -1
GUI_BAR_SIZE = None
GUI_DIRTY = True
LATEST_PT = (-1, -1)
LATEST_RAW_PT = (-1, -1)
MASK_DIRTY = True
MOUSE_FLAGS = 0
WINDOW_SIZE = None
class ZoomTooltip(config)[source]

Bases: object

Zoom tooltip manager used to visualize image details based on mouse location.

__init__(config)[source]

Parses the input config and extracts zoom-related parameters.

refresh(image, mask, mask_colormap, mask_opacity, coords)[source]

Fetches the latest mouse position and updates the zoom window tooltip.

__init__(session_name, config, save_dir, datasets)[source]

Parses the input samples and initializes the anntator GUI elements.

get_mask_path(index)[source]

Returns the path where the mask of a specific sample should be located.

handle_keys()[source]

Fetches the latest keyboard press and updates the annotator state accordingly.

load(index)[source]

Loads the image and mask associated to a specific sample.

static on_mouse(event, x, y, flags, param)[source]

Callback entrypoint for opencv to register mouse movement/clicks.

static on_press(key)[source]

Callback entrypoint for pynput to register keyboard presses.

refresh_gui()[source]

Updates and displays the main window based on the latest changes.

refresh_layers()[source]

Updates the image, mask, and tool display layers based on the latest changes.

run()[source]

Displays the main window and other GUI elements in a loop until it is closed by the user.

thelper.gui.utils module

Graphical User Interface (GUI) utility module.

This module contains various tools and utilities used to instantiate annotators and GUI elements.

thelper.gui.utils.create_annotator(session_name, save_dir, config, datasets)[source]

Instantiates a GUI annotation tool based on the type contained in the config dictionary.

The tool type is expected to be in the configuration dictionary’s annotator field, under the type key. For more information on the configuration, refer to thelper.gui.annotators.Annotator. The instantiated type must be compatible with the constructor signature of thelper.gui.annotators.Annotator. The object’s constructor will be given the full config dictionary.

Parameters:
  • session_name – name of the annotation session used for printing and to create output directories.
  • save_dir – path to the session directory where annotations and other outputs will be saved.
  • config – full configuration dictionary that will be parsed for annotator parameters.
  • datasets – map of named dataset parsers that will provide the data to annotate.
Returns:

The fully-constructed annotator object, ready to begin annotation via its run() function.

thelper.gui.utils.create_key_listener(callback)[source]

Returns a key press listener based on pynput.keyboard (used for mocking).