Iterate over a local project
1. Demo project

2. Download project in Supervisely format


3. Python script
Source code:
Output

Last updated




Last updated
. π¦ (project root)
βββ π ds1 (dataset name)
βΒ Β βββ π ann
βΒ Β βΒ Β βββ π IMG_0748.jpeg.json
βΒ Β βΒ Β βββ π IMG_1836.jpeg.json
βΒ Β βΒ Β βββ π IMG_2084.jpeg.json
βΒ Β βΒ Β βββ π IMG_3861.jpeg.json
βΒ Β βΒ Β βββ π IMG_4451.jpeg.json
βΒ Β βΒ Β βββ π IMG_8144.jpeg.json
βΒ Β βββ π img
βΒ Β βββ πΌοΈ IMG_0748.jpeg
βΒ Β βββ πΌοΈ IMG_1836.jpeg
βΒ Β βββ πΌοΈ IMG_2084.jpeg
βΒ Β βββ πΌοΈ IMG_3861.jpeg
βΒ Β βββ πΌοΈ IMG_4451.jpeg
βΒ Β βββ πΌοΈ IMG_8144.jpeg
βββ π meta.jsonimport os
import json
import supervisely as sly
from tqdm import tqdm
input = "./lemons-fs"
output = "./results"
os.makedirs(output, exist_ok=True)
# Creating Supervisely project from local directory.
project = sly.Project(input, sly.OpenMode.READ)
print("Opened project: ", project.name)
print("Number of images in project:", project.total_items)
# Showing annotations tags and classes.
print(project.meta)
# Iterating over classes in project, showing their names, geometry types and colors.
for obj_class in project.meta.obj_classes:
print(
f"Class '{obj_class.name}': geometry='{obj_class.geometry_type}', color='{obj_class.color}'",
)
# Iterating over tags in project, showing their names and colors.
for tag in project.meta.tag_metas:
print(f"Tag '{tag.name}': color='{tag.color}'")
print("Number of datasets (aka folders) in project:", len(project.datasets))
progress = tqdm(project.datasets, desc="Processing datasets")
for dataset in project.datasets:
# Iterating over images in dataset, using the paths to the images and annotations.
for item_name, image_path, ann_path in dataset.items():
print(f"Item '{item_name}': image='{image_path}', ann='{ann_path}'")
ann_json = json.load(open(ann_path))
ann = sly.Annotation.from_json(ann_json, project.meta)
img = sly.image.read(image_path) # rgb - order
for label in ann.labels:
# Drawing each label on the image.
label.draw(img)
res_image_path = os.path.join(output, item_name)
sly.image.write(res_image_path, img)
# Or alternatively draw annotation (all labels at once) preview with
# ann.draw_pretty(img, output_path=res_image_path)
progress.update(1)Opened project: lemons-fs
Number of images in project: 6
ProjectMeta:
Object Classes
+-------+--------+----------------+--------+
| Name | Shape | Color | Hotkey |
+-------+--------+----------------+--------+
| kiwi | Bitmap | [255, 0, 0] | |
| lemon | Bitmap | [81, 198, 170] | |
+-------+--------+----------------+--------+
Tags
+----------+------------+-----------------+--------+---------------+--------------------+
| Name | Value type | Possible values | Hotkey | Applicable to | Applicable classes |
+----------+------------+-----------------+--------+---------------+--------------------+
+----------+------------+-----------------+--------+---------------+--------------------+
Class 'kiwi': geometry='<class 'supervisely.geometry.bitmap.Bitmap'>', color='[255, 0, 0]'
Class 'lemon': geometry='<class 'supervisely.geometry.bitmap.Bitmap'>', color='[81, 198, 170]'
Number of datasets (aka folders) in project: 1
Item 'IMG_4451.jpeg': image='./lemons-fs/ds1/img/IMG_4451.jpeg', ann='./lemons-fs/ds1/ann/IMG_4451.jpeg.json'
Item 'IMG_0748.jpeg': image='./lemons-fs/ds1/img/IMG_0748.jpeg', ann='./lemons-fs/ds1/ann/IMG_0748.jpeg.json'
Item 'IMG_1836.jpeg': image='./lemons-fs/ds1/img/IMG_1836.jpeg', ann='./lemons-fs/ds1/ann/IMG_1836.jpeg.json'
Item 'IMG_3861.jpeg': image='./lemons-fs/ds1/img/IMG_3861.jpeg', ann='./lemons-fs/ds1/ann/IMG_3861.jpeg.json'
Item 'IMG_2084.jpeg': image='./lemons-fs/ds1/img/IMG_2084.jpeg', ann='./lemons-fs/ds1/ann/IMG_2084.jpeg.json'
Item 'IMG_8144.jpeg': image='./lemons-fs/ds1/img/IMG_8144.jpeg', ann='./lemons-fs/ds1/ann/IMG_8144.jpeg.json'