In this tutorial we will show you how to use sly.GraphNodes class to create data annotation for pose estimation / keypoints detection task. The tutorial illustrates basic upload-download scenario:
create project and dataset on server
upload image
programmatically create annotation and upload it to image
download image and annotation
ℹ️ Everything you need to reproduce : 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.
Step 2. Clone with source code and demo data and create .
git clone https://github.com/supervisely-ecosystem/keypoints-labeling-example
cd keypoints-labeling-example
./create_venv.sh
Step 3. Open repository directory in Visual Studio Code
code -r .
Step 4. Start debugging src/main.py
Python Code
Importing Necessary Libraries
Import necessary libraries:
import supervisely as sly
from supervisely.geometry.graph import Node, KeypointsTemplate
import os
import json
from dotenv import load_dotenv
Before we will start creating our project, let's learn how to create keypoints template - we are going to use it in our project.
Working With Keypoints Template
We will need an image to create and visualize our keypoints template.
Now, when we have successfully created keypoints template, we can start creating keypoints annotation for our project.
Programmatically Create Keypoints Annotation
load_dotenv(os.path.expanduser('~/supervisely.env'))
api = sly.Api.from_env()
my_teams = api.team.get_list()
team = my_teams[0]
workspace = api.workspace.get_list(team.id)[0]
Input image:
Create project and dataset:
project = api.project.create(workspace.id, "Human Pose Estimation", change_name_if_conflict=True)
dataset = api.dataset.create(project.id, "Person with dog", change_name_if_conflict=True)
print(f"Project {project.id} with dataset {dataset.id} are created")
Now let's create annotation class using our keypoints template as a geometry config (unlike other supervisely geometry classes, sly.GraphNodes requires geometry config to be passed - it is necessary for object class initialization):
person = sly.ObjClass("person", geometry_type=sly.GraphNodes, geometry_config=template)
project_meta = sly.ProjectMeta(obj_classes=[person])
api.project.update_meta(project.id, project_meta.to_json())
You can also go to Supervisely platform and check that class with shape "Keypoints" was successfully added to your project: