Video and object tags
How to create, add, update and remove tags from Video and its objects.
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
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
Last updated