Key ID Map

class supervisely_lib.video_annotation.key_id_map.KeyIdMap[source]

Bases: object

KeyIdMap object for VideoAnnotation. It consist from dict with bidict values.

Usage example
key_id_map = KeyIdMap()
print(key_id_map.to_dict())
# Output: {
#     "tags": {},
#     "objects": {},
#     "figures": {},
#     "videos": {}
# }
add_object(key: uuid.UUID, id: int) → None[source]

Add UUID and ID of VideoObject in KeyIdMap.

Parameters
  • key (UUID) – UUID object.

  • id (int) – VideoObject ID.

Returns

None

Return type

NoneType

Usage example
key_id_map = KeyIdMap()
new_uuid = uuid.uuid4() # "0c0033c5b4834d4cbabece4317295f07"
key_id_map.add_object(new_uuid, 1)
print(key_id_map.to_dict())
# Output: {
#     "tags": {},
#     "objects": {
#         "0c0033c5b4834d4cbabece4317295f07": 1
#     },
#     "figures": {},
#     "videos": {}
# }
add_tag(key: uuid.UUID, id: int) → None[source]

Add UUID and ID of VideoTag in KeyIdMap.

Parameters
  • key (UUID) – UUID object.

  • id (int) – VideoTag ID.

Returns

None

Return type

NoneType

Usage example
key_id_map = KeyIdMap()
new_uuid = uuid.uuid4() # "697d005df2a94bb386188c78a61b0a86"
key_id_map.add_tag(new_uuid, 34)
print(key_id_map.to_dict())
# Output: {
#     "tags": {
#         "697d005df2a94bb386188c78a61b0a86": 34
#     },
#     "objects": {},
#     "figures": {},
#     "videos": {}
# }
add_figure(key: uuid.UUID, id: int) → None[source]

Add UUID and ID of VideoFigure in KeyIdMap.

Parameters
  • key (UUID) – UUID object.

  • id (int) – VideoFigure ID.

Returns

None

Return type

NoneType

Usage example
key_id_map = KeyIdMap()
new_uuid = uuid.uuid4() # "ac1018e6673d405590086063af8184ca"
key_id_map.add_figure(new_uuid, 55)
print(key_id_map.to_dict())
# Output: {
#     "tags": {},
#     "objects": {},
#     "figures": {
#         "ac1018e6673d405590086063af8184ca": 55
#     },
#     "videos": {}
# }
add_video(key: uuid.UUID, id: int) → None[source]

Add UUID and ID of VideoAnnotation in KeyIdMap.

Parameters
Returns

None

Return type

NoneType

Usage example
key_id_map = KeyIdMap()
new_uuid = uuid.uuid4() # "775f2c581cec44ca8c10419c20c52fcc"
key_id_map.add_video(new_uuid, 77)
print(key_id_map.to_dict())
# Output: {
#     "tags": {},
#     "objects": {},
#     "figures": {},
#     "videos": {
#         "775f2c581cec44ca8c10419c20c52fcc": 77
#     }
# }
get_object_id(key: uuid.UUID) → int[source]

Get VideoObject ID.

Parameters

key (UUID) – UUID object.

Returns

VideoObject ID

Return type

int

Usage example
obj_uuid = '0c0033c5b4834d4cbabece4317295f07'
obj_id = key_id_map.get_object_id(obj_uuid) # 1
get_tag_id(key: uuid.UUID) → int[source]

Get VideoTag ID.

Parameters

key (UUID) – UUID object.

Returns

VideoTag ID

Return type

int

Usage example
tag_uuid = '697d005df2a94bb386188c78a61b0a86'
tag_id = key_id_map.get_tag_id(tag_uuid) # 34
get_figure_id(key: uuid.UUID) → int[source]

Get VideoFigure ID.

Parameters

key (UUID) – UUID object.

Returns

VideoFigure ID

Return type

int

Usage example
figure_uuid = 'ac1018e6673d405590086063af8184ca'
figure_id = key_id_map.get_figure_id(figure_uuid) # 55
get_video_id(key: uuid.UUID) → int[source]

Get VideoAnnotation ID.

Parameters

key (UUID) – UUID object.

Returns

VideoAnnotation ID

Return type

int

Usage example
video_uuid = '775f2c581cec44ca8c10419c20c52fcc'
video_id = key_id_map.get_video_id(video_uuid) # 77
get_object_key(id: int) → uuid.UUID[source]

Get VideoObject UUID key.

Parameters

key (int) – VideoObject ID.

Returns

UUID object

Return type

UUID

Usage example
obj_id = 1
obj_uuid = key_id_map.get_object_id(obj_id) # '0c0033c5b4834d4cbabece4317295f07'
get_tag_key(id: int) → uuid.UUID[source]

Get VideoTag UUID key.

Parameters

key (int) – VideoTag ID.

Returns

UUID object

Return type

UUID

Usage example
tag_id = 34
tag_uuid = key_id_map.get_tag_key(tag_id) # '697d005df2a94bb386188c78a61b0a86'
get_figure_key(id: int) → uuid.UUID[source]

Get VideoFigure UUID key.

Parameters

key (int) – VideoFigure ID.

Returns

UUID object

Return type

UUID

Usage example
figure_id = 55
figure_uuid = key_id_map.get_figure_key(figure_id) # 'ac1018e6673d405590086063af8184ca'
get_video_key(id: int) → uuid.UUID[source]

Get VideoAnnotation UUID key.

Parameters

key (int) – VideoAnnotation ID.

Returns

UUID object

Return type

UUID

Usage example
video_id = 77
video_uuid = key_id_map.get_video_key(video_id) # '775f2c581cec44ca8c10419c20c52fcc'
to_dict() → dict[source]

Convert the KeyIdMap to a dict(bidict values to dictionary with dict values).

Returns

Json format as a dict

Return type

dict

Usage example
key_id_map = KeyIdMap()
print(key_id_map.to_dict())
# Output: {
#     "tags": {},
#     "objects": {},
#     "figures": {},
#     "videos": {}
# }
dump_json(path: str) → None[source]

Write KeyIdMap in file by given path.

Parameters

path (str) – Target file path.

Returns

None

Return type

NoneType

Usage example
key_id_map.dump_json('/home/admin/work/projects/key_id.json')
classmethod load_json(path: str)supervisely_lib.video_annotation.key_id_map.KeyIdMap[source]

Decoding data from json file with given filename to KeyIdMap.

Parameters

path (str) – Target file path.

Returns

KeyIdMap object

Return type

KeyIdMap

Usage example
new_key_id = KeyIdMap.load_json('/home/admin/work/projects/key_id.json')
classmethod add_tags_to(key_id_map: supervisely_lib.video_annotation.key_id_map.KeyIdMap, keys: List[uuid.UUID], ids: List[int]) → None[source]

Add VideoTag type of instances with given values(keys, ids) to KeyIdMap object.

Parameters
  • key_id_map (KeyIdMap) – KeyIdMap object.

  • key (List[UUID]) – List of UUID objects.

  • id (List[int]) – List of VideoTag IDs.

Returns

None

Return type

NoneType

Usage example
key_id_map = KeyIdMap()
uuid_1 = uuid.uuid4()
tag_id_1 = 1213
uuid_2 = uuid.uuid4()
tag_id_2 = 3686
KeyIdMap.add_tags_to(key_id_map, [uuid_1, uuid_2], [tag_id_1, tag_id_2])
classmethod add_tag_to(key_id_map: supervisely_lib.video_annotation.key_id_map.KeyIdMap, key: uuid.UUID, id: int) → None[source]

Add VideoTag type of instance with given key and id to KeyIdMap object.

Parameters
  • key_id_map (KeyIdMap) – KeyIdMap object.

  • key (UUID) – UUID object.

  • id (int) – VideoTag ID.

Returns

None

Return type

NoneType

Usage example
key_id_map = KeyIdMap()
new_uuid = uuid.uuid4()
new_tag_id = 1213
KeyIdMap.add_tag_to(key_id_map, new_uuid, new_tag_id)
classmethod add_objects_to(key_id_map: supervisely_lib.video_annotation.key_id_map.KeyIdMap, keys: List[uuid.UUID], ids: List[int]) → None[source]

Add VideoObject type of instances with given values(keys, ids) to KeyIdMap object.

Parameters
  • key_id_map (KeyIdMap) – KeyIdMap object.

  • key (List[UUID]) – List of UUID objects.

  • id (List[int]) – List of VideoObject IDs.

Returns

None

Return type

NoneType

Usage example
key_id_map = KeyIdMap()
uuid_1 = uuid.uuid4()
object_id_1 = 23
uuid_2 = uuid.uuid4()
object_id_2 = 57
KeyIdMap.add_objects_to(key_id_map, [uuid_1, uuid_2], [object_id_1, object_id_2])
classmethod add_object_to(key_id_map: supervisely_lib.video_annotation.key_id_map.KeyIdMap, key: uuid.UUID, id: int) → None[source]

Add VideoObject type of instance with given key and id to KeyIdMap object.

Parameters
  • key_id_map (KeyIdMap) – KeyIdMap object.

  • key (UUID) – UUID object.

  • id (int) – VideoObject ID.

Returns

None

Return type

NoneType

Usage example
key_id_map = KeyIdMap()
new_uuid = uuid.uuid4()
new_object_id = 76
KeyIdMap.add_object_to(key_id_map, new_uuid, new_object_id)
classmethod add_figures_to(key_id_map: supervisely_lib.video_annotation.key_id_map.KeyIdMap, keys: List[uuid.UUID], ids: List[int]) → None[source]

Add VideoFigure type of instances with given values(keys, ids) to KeyIdMap object.

Parameters
  • key_id_map (KeyIdMap) – KeyIdMap object.

  • key (List[UUID]) – List of UUID objects.

  • id (List[int]) – List of VideoFigure IDs.

Returns

None

Return type

NoneType

Usage example
key_id_map = KeyIdMap()
uuid_1 = uuid.uuid4()
figure_id_1 = 23
uuid_2 = uuid.uuid4()
figure_id_2 = 57
KeyIdMap.add_figures_to(key_id_map, [uuid_1, uuid_2], [figure_id_1, figure_id_2])
classmethod add_figure_to(key_id_map: supervisely_lib.video_annotation.key_id_map.KeyIdMap, key: uuid.UUID, id: int) → None[source]

Add VideoFigure type of instance with given key and id to KeyIdMap object.

Parameters
  • key_id_map (KeyIdMap) – KeyIdMap object.

  • key (UUID) – UUID object.

  • id (int) – VideoFigure ID.

Returns

None

Return type

NoneType

Usage example
key_id_map = KeyIdMap()
new_uuid = uuid.uuid4()
new_figure_id = 3834
KeyIdMap.add_figure_to(key_id_map, new_uuid, new_figure_id)
classmethod add_videos_to(key_id_map: supervisely_lib.video_annotation.key_id_map.KeyIdMap, keys: List[uuid.UUID], ids: List[int]) → None[source]

Add VideoAnnotation type of instances with given values(keys, ids) to KeyIdMap object.

Parameters
  • key_id_map (KeyIdMap) – KeyIdMap object.

  • key (List[UUID]) – List of UUID objects.

  • id (List[int]) – List of VideoAnnotation IDs.

Returns

None

Return type

NoneType

Usage example
key_id_map = KeyIdMap()
uuid_1 = uuid.uuid4()
video_id_1 = 567
uuid_2 = uuid.uuid4()
video_id_2 = 5200
KeyIdMap.add_videos_to(key_id_map, [uuid_1, uuid_2], [video_id_1, video_id_2])
classmethod add_video_to(key_id_map: supervisely_lib.video_annotation.key_id_map.KeyIdMap, key: uuid.UUID, id: int) → None[source]

Add VideoAnnotation type of instance with given key and id to KeyIdMap object.

Parameters
Returns

None

Return type

NoneType

Usage example
key_id_map = KeyIdMap()
new_uuid = uuid.uuid4()
new_video_id = 3834
KeyIdMap.add_video_to(key_id_map, new_uuid, new_video_id)