Video Tag Collection

class supervisely_lib.video_annotation.video_tag_collection.VideoTagCollection(items=None)[source]

Bases: supervisely_lib.annotation.tag_collection.TagCollection

Collection with VideoTag instances. VideoTagCollection object is immutable.

Usage example
from supervisely_lib.video_annotation.video_tag import VideoTag
from supervisely_lib.video_annotation.video_tag_collection import VideoTagCollection

# Create two VideoTags for collection
meta_car = sly.TagMeta('car_tag', sly.TagValueType.ANY_STRING)
car_tag = VideoTag(meta_car, value='acura')
meta_bus = sly.TagMeta('bus_tag', sly.TagValueType.ANY_STRING)
bus_tag = VideoTag(meta_bus, value='volvo')

# Create VideoTagCollection
tags = VideoTagCollection([car_tag, bus_tag])
tags_json = tags.to_json()
print(tags_json)
# Output: [
#     {
#         "name": "car_tag",
#         "value": "acura",
#         "key": "378408fcb6854305a38fed7c996f4901"
#     },
#     {
#         "name": "bus_tag",
#         "value": "volvo",
#         "key": "0c63174878204faea67c4025adec1e2a"
#     }
# ]

# Add item to VideoTagCollection
meta_truck = sly.TagMeta('truck_tag', sly.TagValueType.NONE)
truck_tag = VideoTag(meta_truck)
# Remember that VideoTagCollection is immutable, and we need to assign new instance of VideoTagCollection to a new variable
new_tags = tags.add(truck_tag)
new_tags_json = new_tags.to_json()
print(new_tags_json)
# Output: [
#     {
#         "name": "car_tag",
#         "value": "acura",
#         "key": "3d33f1685dab44da9b55d67bab3937e9"
#     },
#     {
#         "name": "bus_tag",
#         "value": "volvo",
#         "key": "7c52c168a22b47a5b39fbcdef94b0140"
#     },
#     {
#         "name": "truck_tag",
#         "key": "7188242d230b4d2783c588cc2eca5ff8"
#     }
# ]

# You can also add multiple items to collection
meta_truck = sly.TagMeta('truck_tag', sly.TagValueType.NONE)
truck_tag = VideoTag(meta_truck)
meta_train = sly.TagMeta('train_tag', sly.TagValueType.ANY_NUMBER)
train_tag = VideoTag(meta_train, value=777)
new_tags = tags.add_items([truck_tag, train_tag])
new_tags_json = new_tags.to_json()
print(new_tags_json)
# Output: [
#     {
#         "name": "car_tag",
#         "value": "acura",
#         "key": "03b052c464d84d5db6451b86f3bdef79"
#     },
#     {
#         "name": "bus_tag",
#         "value": "volvo",
#         "key": "0f7dd8fb6f8c41da9e68e64d3186df15"
#     },
#     {
#         "name": "truck_tag",
#         "key": "fc01af7c70154771b7253b6a94484179"
#     },
#     {
#         "name": "train_tag",
#         "value": 777,
#         "key": "6ce5118181074a52b74dee9335fa292d"
#     }
# ]

# Intersection, finds intersection of given list of VideoTag instances with collection items
intersect_tags = tags.intersection([bus_tag])
intersect_tags_json = intersect_tags.to_json()
print(intersect_tags_json)
# Output: [
#     {
#         "name": "bus_tag",
#         "value": "volvo",
#         "key": "13d77d8c848e4a3ebeb710bf5f3f38a6"
#     }
# ]

# Difference, finds difference between collection and given list of VideoTag
diff_tags = tags.difference([bus_tag])
diff_tags_json = diff_tags.to_json()
print(diff_tags_json)
# Output: [
#     {
#         "name": "car_tag",
#         "value": "acura",
#         "key": "341b9fc077e142c0956d5cf985d705c1"
#     }
# ]

# Merge, merges collection and given list of VideoTagCollection
meta_truck = sly.TagMeta('truck_tag', sly.TagValueType.NONE)
truck_tag = VideoTag(meta_truck)
meta_train = sly.TagMeta('train_tag', sly.TagValueType.ANY_NUMBER)
train_tag = VideoTag(meta_train, value=777)
over_tags = VideoTagCollection([truck_tag, train_tag])
# Merge
merge_tags = tags.merge(over_tags)
merge_tags_json = merge_tags.to_json()
print(merge_tags_json)
# Output: [
#     {
#         "name": "car_tag",
#         "value": "acura",
#         "key": "3bfde60091a24dd493485f2b80364736"
#     },
#     {
#         "name": "bus_tag",
#         "value": "volvo",
#         "key": "dac5b07954064c78acadfa71161f6998"
#     },
#     {
#         "name": "truck_tag",
#         "key": "a46aac4499574afc81d41d2bb061a3c6"
#     },
#     {
#         "name": "train_tag",
#         "value": 777,
#         "key": "bf5b1667383449478694fb6349d7b16c"
#     }
# ]
item_type

alias of supervisely_lib.video_annotation.video_tag.VideoTag

to_json(key_id_map: Optional[supervisely_lib.video_annotation.key_id_map.KeyIdMap] = None) → List[dict][source]

Convert the VideoTagCollection to a list of json dicts. Read more about Supervisely format.

Parameters

key_id_map (KeyIdMap, optional) – KeyIdMap object.

Returns

List of dicts in json format

Return type

List[dict]

Usage example
from supervisely_lib.video_annotation.video_tag import VideoTag
from supervisely_lib.video_annotation.video_tag_collection import VideoTagCollection

meta_car = sly.TagMeta('car_tag', sly.TagValueType.ANY_STRING)
car_tag = VideoTag(meta_car, value='acura')
meta_bus = sly.TagMeta('bus_tag', sly.TagValueType.ANY_STRING)
bus_tag = VideoTag(meta_bus, value='volvo')
tags = VideoTagCollection([car_tag, bus_tag])
tags_json = tags.to_json()
print(tags_json)
# Output: [
#     {
#         "name": "car_tag",
#         "value": "acura",
#         "key": "378408fcb6854305a38fed7c996f4901"
#     },
#     {
#         "name": "bus_tag",
#         "value": "volvo",
#         "key": "0c63174878204faea67c4025adec1e2a"
#     }
# ]
classmethod from_json(data: List[dict], tag_meta_collection: supervisely_lib.annotation.tag_meta_collection.TagMetaCollection, key_id_map: Optional[supervisely_lib.video_annotation.key_id_map.KeyIdMap] = None)supervisely_lib.video_annotation.video_tag_collection.VideoTagCollection[source]

Convert a list of json dicts to VideoTagCollection. Read more about Supervisely format.

Parameters
  • data (List[dict]) – List with dicts in json format.

  • project_meta (TagMetaCollection) – Input TagMetaCollection object.

  • key_id_map (KeyIdMap, optional) – KeyIdMap object.

Returns

VideoTagCollection object

Return type

VideoTagCollection

Usage example
tags_json = [
    {
        "name": "car_tag",
        "value": "acura",
    },
    {
        "name": "bus_tag",
        "value": "volvo",
    }
]
meta_car = sly.TagMeta('car_tag', sly.TagValueType.ANY_STRING)
meta_bus = sly.TagMeta('bus_tag', sly.TagValueType.ANY_STRING)
meta_collection = sly.TagMetaCollection([meta_car, meta_bus])

tags = VideoTagCollection.from_json(tags_json, meta_collection)