For the complete documentation index, see llms.txt. This page is also available as Markdown.

Video and object tags

How to create, add, update and remove tags from Video and its objects, and how to constrain frame-based tags by length.

Introduction

In this tutorial, you will learn how to create new tags for Video, its objects or frames and assign them, update its values or remove at all using the Supervisely SDK.

Supervisely supports different types of tags:

  • NONE

  • ANY_NUMBER

  • ANY_STRING

  • ONEOF_STRING

  • DATE

And could be applied to:

  • ALL

  • IMAGES_ONLY - in our case this indicates Videos

  • OBJECTS_ONLY

You can find all the information about those types in the Tags in Annotations section and SDK documentation.

You can learn more about working with Video using Supervisely SDK and what Annotations for Video are.

Everything you need to reproduce this tutorial is on GitHub: source code, Visual Studio Code configuration, and a shell script for creating virtual env.

How to debug this tutorial

Step 1. Prepare ~/supervisely.env file with credentials. Learn more here.

Step 2. Clone repository with source code and create Virtual Environment.

Step 3. Open repository directory in Visual Studio Code.

Step 4. Create video project, for example, using this tutorial Spatial labels on videos.

There you see project classes after project initialization.

Project tags metadata after its initialization. This data is empty.

Visualization in Labeling Tool before we starting add tags.

Step 5. Change Workspace ID in local.env file by copying the ID from the context menu of the workspace. Do the same for Project ID and Dataset ID .

Step 6. Start debugging src/main.py

Python Code

Import libraries

Init API client

Init api for communicating with Supervisely Instance. First, we load environment variables with credentials, Project and Dataset IDs:

With next lines we will get values from local.env.

By using these IDs, we can retrieve the project metadata and annotations, and define the values needed for the following operations.

Define function to work with metadata

This function is used to recreate the source project metadata with new tag metadata. Right after updating the metadata, we need to obtain added metadata again to work with it in the next steps. In case a tag with the tag_name already exists in the metadata, we could just use it if it fits our requirements. If this tag doesn't meet our requirements, it would be better to create a new one with a different name.

Create new tag metadata for video

Here, we are creating metadata for a video tag and using the function from the previous step to insert it into our project.

Create new tag for video and its frames

When you pass information from tag metadata using its ID to the object, a new tag is created and appended.

To add a tag with value, you must define the value argument with possible values.

If you want to add a tag to frames, you must define the frame_range argument.

Visualization in Labeling Tool with new tags.

Update tag value and frame range for video

Also, if you need to correct tag values or frames, you can easily do so as follows:

Delete tag

To remove a tag, all you need is its ID.

Please note that you are only deleting the tag from the object. To remove a tag from the project (TagMeta), you need to use other SDK methods.

Create new tag metadatas for objects in video

The process is the same as for video, but now we strictly define the applicable_to parameter to specify which entities these tags can be added to. It is not necessary and depends solely on your desire to limit the types other than objects.

Create new tag for object and frames with this object

There's nothing new that you haven't seen already, just added some lines to handle objects according to their classes. Collects only oranges tag ids for further processing.

Visualization in Labeling Tool with new tags.

Update tag value and frame range for object

To correct tag values for the first orange in list, do so as follows:

Delete tag from object

Managing project tags (TagMeta)

Everything above adds, edits and removes tags on a video or an object. The tag itself — its name, value type, scope and constraints — lives in the project meta as a TagMeta. The refresh_meta helper at the start of this tutorial creates one by rebuilding the whole project meta, which is the right approach when you are preparing many classes and tags at once.

When you only need to add or edit a tag, there are direct methods that take a TagMeta and touch nothing else:

Several at once, in one request:

To edit an existing tag, pass its ID. This is a partial update — only the arguments you pass are changed:

project_id is needed because the endpoint requires the tag's name and colour in every request; passing it lets the SDK read the current values for you. You can also pass name and color yourself instead.

applicable_classes takes class names, exactly as TagMeta.applicable_classes does — the SDK resolves them to the IDs the API expects. An empty list removes the restriction. A name that the project does not have raises a ValueError before anything is sent.

These methods are available for every entity type: api.video.tag, api.image.tag, api.volume.tag, api.pointcloud.tag.

Frame range length limits

A frame-based tag can carry a minimum and a maximum length, in frames, measured on the finished tag. Use them when a tag is only meaningful over a certain span — a "running" segment shorter than five frames is more likely a mislabel than a real event. The limits apply to videos and point cloud episodes.

A labeler finishing a "running" tag shorter than 5 frames or longer than 30 now gets rejected by the platform.

Three things are worth knowing about how the limits behave:

  • Length is inclusive. Frames 10 to 12 are a length of 3, not 2.

  • 0 means "no limit". There is no separate on/off switch — a limit is active only while its value is above zero, so 0 (or None) disables it. That is also how you remove a limit later.

  • Only finished tags are checked. A tag being drawn is not validated until it is completed, so a labeler can pass through invalid lengths on the way.

Reading the limits back from the project meta:

You can also check a range yourself before sending it, using the same inclusive arithmetic the platform applies:

Changing the limits

On an existing tag, by ID. Pass 0 to drop a limit and leave an argument out to keep it as it is:

Or through the project meta, which is convenient when you are already editing it. Note that with_frame_range_length_limits replaces both limits, so calling it with no arguments clears them:

Last updated