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 3. Open repository directory in Visual Studio Code.
Step 4. change ✅ workspace ID ✅ in local.env file by copying the ID from the context menu of the workspace. A new project with annotated videos will be created in the workspace you define:
Copy workspace ID from context menu
Step 5. Start debugging src/main.py
Debug tutorial in Visual Studio Code
Python Code
Import libraries
Init API client
Init api for communicating with Supervisely Instance. First, we load environment variables with credentials and workspace ID:
With next lines we will check the you did everything right - API client initialized with correct credentials and you defined the correct workspace ID in local.env.
Create project
Create empty project with name "Demo" with one dataset "orange & kiwi" in your workspace on server. If the project with the same name exists in your dataset, it will be automatically renamed (Demo_001, Demo_002, etc ...) to avoid name collisions.
Upload video to the dataset on server
Create annotation classes and update project meta
Color will be automatically generated if the class was created without color argument.
The next step is to create ProjectMeta - a collection of annotation classes and tags that will be available for labeling in the project.
And finally, we need to set up classes in our project on server:
Prepare source data
Create video objects
Create masks, rectangles, frames and figures
We are going to create ten masks from the following black and white images:
Ten black-and-white masks for every orange
Mask has to be the same size as the video
Supervisely SDK allows creating masks from NumPy arrays with the following values:
git clone https://github.com/supervisely-ecosystem/video-figures
cd video-figures
./create_venv.sh
code -r .
WORKSPACE_ID=507 # ⬅️ change value
import os
from os.path import join
from dotenv import load_dotenv
import supervisely as sly
load_dotenv("local.env")
load_dotenv(os.path.expanduser("~/supervisely.env"))
api = sly.Api()
workspace_id = sly.env.workspace_id()
workspace = api.workspace.get_info_by_id(workspace_id)
if workspace is None:
print("you should put correct workspaceId value to local.env")
raise ValueError(f"Workspace with id={workspace_id} not found")
project = api.project.create(
workspace.id,
name="Demo",
type=sly.ProjectType.VIDEOS,
change_name_if_conflict=True,
)
dataset = api.dataset.create(project.id, name="orange & kiwi")
print(f"Project has been sucessfully created, id={project.id}")
video_path = "data/orange_kiwi.mp4"
video_name = sly.fs.get_file_name_with_ext(video_path)
video_info = api.video.upload_path(dataset.id, video_name, video_path)
print(f"Video has been sucessfully uploaded, id={video_info.id}")