How to make ClearML not upload annotations twice when they have the same ID?

Question:

The following uploads two annotations, though I expected there to be only one

from typing import List
from allegroai import Dataset, DatasetVersion, SingleFrame, DataView
from allegroai.dataframe.annotation import BoundingBox2D

allegro_frame = SingleFrame(
    source="/irrelevant/source.png"
)
ann_id = "the_id"
label = "the_label"
annotation = BoundingBox2D(id=ann_id)
allegro_frame.add_annotation(id=ann_id, box2d_xywh=(100, 100, 100, 100), labels=(label,))
allegro_frame.add_annotation(id=ann_id, box2d_xywh=(100, 100, 100, 100), labels=(label,))

allegro_frames: List[SingleFrame] = [
    allegro_frame
]

dataset_name = r"clml_test_dataset"
version_name = r"clml_test_version"
dataset = Dataset.create(dataset_name=dataset_name)
version = DatasetVersion.create_version(dataset_name=dataset_name, version_name=version_name)
version.add_frames(allegro_frames)

What’s the correct way to make only one annotation be uploaded for the frame?

Asked By: Gulzar

||

Answers:

Disclaimer: I’m part of the ClearML team

Annotation ID is essentially a user-data field – not the SDK nor the server validate or enforce uniqueness. To enforce it yourself, you can just use allegro_frame.remove_annotations(id=ann_id) before adding your annotation – this will remove any existing annotation with the given user ID.

Answered By: Martin.B
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.