Label configuration

Using the python package to upload your existing label configuration.

Create a Label Configuration

Before you can start setting up your label configuration you need to start by initializing a label_config object.

from datagym import LabelConfig
label_config = LabelConfig()

In DATAGYM there are two types of entries; classifications and geometries. See the chapter on label configuration to learn more.

Label configuration

Geometries

Geometries can be added directly to the label config with just an entry key and entry value. The entry key will be the name for the label export while the entry value is shown inside of the DATAGYM workspace. Optionally you can also pass a shortcut [0-9] and a color for the geometry.

# Adding a polygon
label_config.add_polygon(
    entry_key="polygon1",
    entry_value="polygon1"
)

# Adding a bounding box
label_config.add_rectangle(
    entry_key="rectangle1",
    entry_value="rectangle1"
)

# Adding a line
label_config.add_line(
    entry_key="line1",
    entry_value="line1"
)

# Adding a point
label_config.add_point(
    entry_key="point1",
    entry_value="point1"
)

Classification

Classifications can either refer directly to the image (global classification) or also to another classification or geometry (nested classification). Besides the entry key and entry value the options dict is required for both the checklist and the select configuration entries.

## Global classifications
# Adding a free text tag
label_config.add_freetext(
    entry_key="caption",
    entry_value="caption"
)

# Adding a checklist tag with options
label_config.add_checklist(
    entry_key="caption",
    entry_value="caption",
    options_dict={"option1": "option1", "option2": "option2"}
)

# Adding a select tag with options
label_config.add_select(
    entry_key="caption",
    entry_value="caption",
    options_dict={"option1": "option1", "option2": "option2"}
)

For nested classifications you can just add the classification of your choice to any existing entry inside your label config.

## Global classifications
# Adding a free text tag to an existing polygon
polygon = label_config.add_polygon(
    entry_key="polygon1",
    entry_value="polygon1"
)

polygon.add_freetext(
    entry_key="caption",
    entry_value="caption"
)

# Adding a checklist tag with options to an existing select tag
select = label_config.add_select(
    entry_key="caption",
    entry_value="caption",
    options_dict={"option1": "option1", "option2": "option2"}
)
select.add_checklist(
    entry_key="caption",
    entry_value="caption",
    options_dict={"option1": "option1", "option2": "option2"}
)

Uploading your finished label configuration

Careful with using the upload-label-config method. This deletes your existing label configuration and all of your existing labels in this project.

Uploading your label configuration is easily done with just one line of code. However be careful as this is not something that you want to do with a project with important labels in it.

project = client.get_project_by_name(project_name="<Your project name>"")

client.upload_label_config(project.label_config_id, label_config.toJson())

Last updated