Uploading Classification Annotations

This notebook shows how to upload classification annotations, for the whole image or for some frames:

  • category: the value comes from a fixed list set up in the project (e.g. Normal / Displaced)

  • text: any free text

  • label: marks that something is present, with no value

Our example project looks like this:

image.png

Setup

[ ]:
from datamint import Api

api = Api()

PROJECT_NAME = "Example Project"
resources = list(api.resources.get_list(project_name=PROJECT_NAME))
resource = resources[0]

Category annotations

The value must be one of the values set up in the project. On the web the user picks it from a dropdown.

[ ]:
api.annotations.add_category_annotation(resource, identifier='position', value='Displaced')

See more details in the documentation AnnotationsApi.add_category_annotation.

Text annotations

The value can be any free text. On the web the user types it in.

[ ]:
api.annotations.add_text_annotation(resource, identifier='findings', value='small fracture line near the joint')

Label annotations

A label has no value: it only marks that something is present.

[ ]:
api.annotations.add_label_annotation(resource, identifier='Fracture')

Frame annotations

All the methods above also accept frames. Without frames the annotation covers the whole image.

  • frame_index: a single frame, 0-based

  • frame_range: a range of frames as (start, end), where end is not included, like Python’s range(). (42, 46) covers frames 42, 43, 44 and 45.

[ ]:
api.annotations.add_category_annotation(resource, identifier='position', value='Normal', frame_index=3)
api.annotations.add_category_annotation(resource, identifier='position', value='Displaced', frame_range=(42, 46))
api.annotations.add_text_annotation(resource, identifier='findings', value='motion blur', frame_range=(10, 20))
api.annotations.add_label_annotation(resource, identifier='Fracture', frame_range=(42, 46))

Setting all frames at once

set_frame_ranges sets the whole timeline of one annotation in a single call. It replaces what you uploaded before for that identifier, so anything not listed is removed. Use None as the value for a label.

get_frame_ranges reads the frame annotations back, with the frames as (start, end) ranges.

[ ]:
api.annotations.set_frame_ranges(resource, identifier='position', type='category',
                                 values={'Displaced': [(0, 10), (20, 30)],
                                         'Normal': [(10, 20)]})

for record in api.annotations.get_frame_ranges(resource):
    print(record['identifier'], record['text_value'], record['frame_ranges'])

See more details in the documentation: