Create annotations
How to bulk create localizations and states with tator-py.
Tator is designed to manage large numbers of annotations. For dense tracking algorithms, this can equate to multiple localizations per frame, and tens of thousands of localizations per video. Tator-py includes utilities for chunked creation of large numbers of annotations. First we must create a list of dictionaries conforming to the schema specified for LocalizationSpec or StateSpec, then we use the chunked_create
utility:
import tator
api = tator.get_api('https://cloud.tator.io', TOKEN)
spec = [{
'media_id': MEDIA_ID,
'type': LOCALIZATION_TYPE,
'frame': FRAME_NUMBER,
'x': 0.0,
'y': 0.0,
'width': 0.5,
'height': 0.5,
# Add user-defined attributes here
},
# Insert many more localizations here
]
created_ids = []
for response in tator.util.chunked_create(api.create_localization_list, PROJECT_ID,
localization_spec=spec):
created_ids += response.id
print(f"Created {len(created_ids)} localizations!")
The utility will do multiple requests, creating localizations in batches of 500, the maximum number of localizations that can be created in a single request. For states, the call to chunked_create
is only slightly different. Starting from a list of state specs:
created_ids = []
for response in tator.util.chunked_create(api.create_state_list, PROJECT_ID,
state_spec=spec):
created_ids += response.id
print(f"Created {len(created_ids)} states!")