CompareAnnotations

Introduction

CompareAnnotations is a simple widget that allows you to compare different annotations for one image. It can be useful for comparing annotations of different applied NN models. Widget doesn't support Keypoints shape. This widget is based on GridGallery widget.

Function signature

CompareAnnotations(
        columns_number=5,
        default_opacity=0.5,
        fill_rectangle=True,
        border_width=3,
        view_height=None,
        empty_message="No image was provided",
        widget_id=None,
)

Parameters

Parameters
Type
Description

columns_number

int

Determines number of columns in widget

default_opacity

float

Figures opacity

fill_rectangle

bool

If False labels with shape Rectangle will be hollow

border_width

int

Border width

view_height

int

Set fixed gallery height in px

empty_message

str

If no image is given, this message will be displayed.

widget_id

str

Id of the widget

columns_number

Determines the number of columns on CompareAnnotations.

type: int

default value: 1

default_opacity

Figures opacity.

type: float

default value: 0.5

fill_rectangle

If False labels with shape Rectangle will be hollow.

type: bool

default value: true

border_width

Determines border width to rectangle figures.

type: int

default value: 3

view_height

Set fixed gallery height in px.

type: int

default value: None

empty_message

If no image is given, this message will be displayed.

type: str

default value: "No image was provided"

widget_id

ID of the widget.

type: str

default value: None

Methods and attributes

Attributes and Methods
Description

image_url()

Returns current image URL

set_image_url()

Set current image by URL

append()

Add annotations to gallery

is_empty()

Checks whether image is set or not

clean_up()

Clean up widget from image and annotations

Mini App Example

In this example, we will use CompareAnnotations widget to display different annotations for one image. We will modify and duplicate an existing image annotation and slightly alter the labels on it, to make them different. All labels will be converted to shape Rectangle.

You can find this example in our Github repository:

supervisely-ecosystem/ui-widgets-demos/compare-data/005_compare_annotations/src/main.py

Import libraries

Init API client

First, we load environment variables with credentials and init API for communicating with Supervisely Instance:

Get project ID and dataset ID

This app requires that you project have at least 2 images in it. If you don't have any projects, you can get one from Supervisely Ecosystem.

Get images and annotations infos

Option 1. Collect image names, URLs, annotations and generate annotation names from server

Option 2. You can also serve images from your local machine, using a static directory

Sort lists of images and annotations to make sure they are in the correct order.

Read annotations from local .json files

Create a function to modify the annotation

Iterate over column numbers and append modified annotations to widget

We iterate over column numbers for demo purposes to show all annotations in one line.

Create buttons for changing current image and cleaning up widget

Create app layout

Prepare a layout for app using Card widget with the content parameter and place widget that we've just created in the Container widget.

Create app using layout

Create an app object with layout parameter.

In case you want to use a static directory, you need to pass it to the Application.

Create a callback functions for buttons

Last updated

Was this helpful?