Video Tag

class supervisely_lib.video_annotation.video_tag.VideoTag(meta: supervisely_lib.annotation.tag_meta.TagMeta, value: Optional[str] = None, frame_range: Optional[Tuple[int, int]] = None, key: Optional[supervisely_lib.video_annotation.key_id_map.KeyIdMap] = None, sly_id: Optional[int] = None, labeler_login: Optional[str] = None, updated_at: Optional[str] = None, created_at: Optional[str] = None)[source]

Bases: supervisely_lib.annotation.tag.Tag

VideoTag object for VideoAnnotation. VideoTag object is immutable.

Parameters
  • meta (TagMeta) – General information about Video Tag.

  • value (str or int or None, optional) – Video Tag value. Depends on TagValueType of TagMeta.

  • frame_range (Tuple[int, int] or List[int, int], optional) – Video Tag frame range.

  • key (KeyIdMap, optional) – KeyIdMap object.

  • sly_id (int, optional) – Video Tag ID in Supervisely.

  • labeler_login (str, optional) – Login of user who created VideoTag.

  • updated_at (str, optional) – Date and Time when VideoTag was modified last. Date Format: Year:Month:Day:Hour:Minute:Seconds. Example: ‘2021-01-22T19:37:50.158Z’.

  • created_at (str, optional) – Date and Time when VideoTag was created. Date Format is the same as in “updated_at” parameter.

Usage example
from supervisely_lib.video_annotation.video_tag import VideoTag

meta_dog = sly.TagMeta('dog', sly.TagValueType.NONE)
# Now we can create a VideoTag using our TagMeta
tag_dog = VideoTag(meta_dog)
# When you are creating a new Tag
# Tag.value is automatically cross-checked against your TagMeta value type to make sure the value is valid.
# If we now try to add a value to our newly created Tag, we receive "ValueError", because our TagMeta value type is "NONE"
tag_dog = VideoTag(meta_dog, value="Husky")
# Output: ValueError: Tag dog can not have value Husky

# Let's create another Tag with a string value type and frame range
meta_cat = sly.TagMeta('cat', sly.TagValueType.ANY_STRING)
tag_cat = VideoTag(meta_cat, value="Fluffy", frame_range=(5, 10))

# Now let's create a Tag using TagMeta with "ONEOF_STRING" value type
# In order to use "oneof_string value type", you must initialize a variable with possible values(see class TagMeta for more information)
colors = ["brown", "white", "black", "red", "chocolate", "gold", "grey"]
meta_coat_color = sly.TagMeta('coat color', sly.TagValueType.ONEOF_STRING, possible_values=colors)
tag_coat_color = VideoTag(meta_coat_color, value="white", frame_range=(15, 20))

# If given value is not in a list of possible Tags, ValueError will be raised
tag_coat_color = VideoTag(meta_coat_color, value="yellow")
# Output: ValueError: Tag coat color can not have value yellow
property frame_range

VideoTag frame range.

Returns

Range of frames for current VideoTag

Return type

List[int, int]

Usage example
cat_range = tag_cat.frame_range # [5, 10]
key()[source]
to_json(key_id_map: Optional[supervisely_lib.video_annotation.key_id_map.KeyIdMap] = None) → dict[source]

Convert the VideoTag to a json dict. Read more about Supervisely format.

Parameters

key_id_map (KeyIdMap, optional) – Key ID Map object.

Returns

Json format as a dict

Return type

dict

Usage example
from supervisely_lib.video_annotation.video_tag import VideoTag
meta_dog = sly.TagMeta('dog', sly.TagValueType.NONE)
tag_dog = VideoTag(meta_dog)
tag_dog_json = tag_dog.to_json()
print(tag_dog_json)
# Output: {
#     "name": "dog",
#     "key": "058ad7993a534082b4d94cc52542a97d"
# }
classmethod from_json(data: 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.VideoTag[source]

Convert a json dict to VideoTag. Read more about Supervisely format.

Parameters
Returns

VideoTag object

Return type

VideoTag

Usage example
tag_cat_json = {
    "name": "cat",
    "value": "Fluffy",
    "frameRange": [
        5,
        10
    ]
}

from supervisely_lib.video_annotation.video_tag import VideoTag
meta_cat = sly.TagMeta('cat', sly.TagValueType.ANY_STRING)
meta_collection = sly.TagMetaCollection([meta_cat])
tag_cat = VideoTag.from_json(tag_cat_json, meta_collection)
get_compact_str() → str[source]

Get string with information about VideoTag: name, value and range of frames.

Returns

Information about VideoTag object

Return type

str

Usage example
from supervisely_lib.video_annotation.video_tag import VideoTag
meta_cat = sly.TagMeta('cat', sly.TagValueType.ANY_STRING)
tag_cat = VideoTag(meta_cat, value="Fluffy", frame_range=(5, 10))
compact_tag_cat = tag_cat.get_compact_str()
print(compact_tag_cat) # cat:Fluffy[5 - 10]
clone(meta: Optional[supervisely_lib.annotation.tag_meta.TagMeta] = None, value: Optional[str] = None, frame_range: Optional[Tuple[int, int]] = None, key: Optional[supervisely_lib.video_annotation.key_id_map.KeyIdMap] = None, sly_id: Optional[int] = None, labeler_login: Optional[str] = None, updated_at: Optional[str] = None, created_at: Optional[str] = None)supervisely_lib.video_annotation.video_tag.VideoTag[source]

Makes a copy of VideoTag with new fields, if fields are given, otherwise it will use fields of the original VideoTag.

Parameters
  • meta (TagMeta, optional) – General information about VideoTag.

  • value (str or int or None, optional) – VideoTag value. Depends on TagValueType of TagMeta.

  • frame_range (Tuple[int, int] or List[int, int], optional) – VideoTag frame range.

  • key (KeyIdMap, optional) – KeyIdMap object.

  • sly_id (int, optional) – VideoTag ID in Supervisely.

  • labeler_login (str, optional) – Login of user who created VideoTag.

  • updated_at (str, optional) – Date and Time when VideoTag was modified last. Date Format: Year:Month:Day:Hour:Minute:Seconds. Example: ‘2021-01-22T19:37:50.158Z’.

  • created_at (str, optional) – Date and Time when VideoTag was created. Date Format is the same as in “updated_at” parameter.

Usage example
from supervisely_lib.video_annotation.video_tag import VideoTag

meta_car = sly.TagMeta('car_tag', sly.TagValueType.ANY_STRING)
car_tag = VideoTag(meta_car, value='acura', frame_range=(7, 9))

meta_bus = sly.TagMeta('bus', sly.TagValueType.ANY_STRING)
new_tag = car_tag.clone(meta=meta_bus, frame_range=(15, 129), key=car_tag.key())
new_tag_json = new_tag.to_json()
print(new_tag_json)
# Output: {
#     "name": "bus",
#     "value": "acura",
#     "frameRange": [
#         15,
#         129
#     ],
#     "key": "360438485fd34264921ca19bd43b0b71"
# }