Notebooks

Download project

iPython Project Created 4 days ago Free
How to download project (images + annotations)
Free Signup

Download project

How to download Project (images + annotations) from Supervisely to local folder

Input:

  • Existing Project in Supervisely

Output:

  • Supervisely format Project in local folder

Configuration

Edit the following settings for your own case

In [1]:
import supervisely_lib as sly
import os
In [2]:
team_name = "jupyter_tutorials"
workspace_name = "First Workspace"
project_name = "tutorial_project"
save_directory = './tutorial_project'

# Obtain server address and your api_token from environment variables
# Edit those values if you run this notebook on your own PC
address = os.environ['SERVER_ADDRESS']
token = os.environ['API_TOKEN']
In [3]:
# Initialize API object
api = sly.Api(address, token)

Verify input values

Test that context (team / workspace / project) exists

In [4]:
# get IDs of team, workspace and project by names

team = api.team.get_info_by_name(team_name)
if team is None:
    raise RuntimeError("Team {!r} not found".format(team_name))

workspace = api.workspace.get_info_by_name(team.id, workspace_name)
if workspace is None:
    raise RuntimeError("Workspace {!r} not found".format(workspace_name))
    
project = api.project.get_info_by_name(workspace.id, project_name)
if project is None:
    raise RuntimeError("Project {!r} not found".format(project_name))
    
print("Team: id={}, name={}".format(team.id, team.name))
print("Workspace: id={}, name={}".format(workspace.id, workspace.name))
print("Project: id={}, name={}".format(project.id, project.name))
Out [4]:
Team: id=30, name=jupyter_tutorials
Workspace: id=71, name=First Workspace
Project: id=864, name=tutorial_project

Create local Project and download remote images

In [5]:
# create Project object for writing data in supervisely format  
project_fs = sly.Project(save_directory, sly.OpenMode.CREATE)
In [6]:
# download meta of remote project and save it to directory 
meta_json = api.project.get_meta(project.id)
meta = sly.ProjectMeta.from_json(meta_json)
project_fs.set_meta(meta)
In [7]:
# iterate over remote datasets and images, download image and corresponding annotation, save item (img+ann pair) to directory 
for dataset in api.dataset.get_list(project.id):
    dataset_fs = project_fs.create_dataset(dataset.name)
    for img_info in api.image.get_list(dataset.id):
        ann_info = api.annotation.download(img_info.id)
        ann = sly.Annotation.from_json(ann_info.annotation, meta)
        img = api.image.download_np(img_info.id)
        dataset_fs.add_item_np(img_info.name, img, img_info.ext, ann)
In [8]:
print("Project {!r} has been successfully downloaded".format(project_name))
print("Total number of images: ", project_fs.total_items)
Out [8]:
Project 'tutorial_project' has been successfully downloaded
Total number of images:  5
In [9]:
# create tar archive in order to download project as file from jupyter lab
sly.fs.archive_directory('tutorial_project', tar_path='tutorial_project.tar')

# remove project folder if need
sly.fs.remove_dir('tutorial_project')

More Info

ID
26
First released
4 days ago
Last updated
3 hours ago

Owner

s