Supervisely
About SuperviselyEcosystemContact usSlack
  • 💻Supervisely Developer Portal
  • 🎉Getting Started
    • Installation
    • Basics of authentication
    • Intro to Python SDK
    • Environment variables
    • Supervisely annotation format
      • Project Structure
      • Project Meta: Classes, Tags, Settings
      • Objects
      • Tags
      • Image Annotation
      • Video Annotation
      • Point Clouds Annotation
      • Point Cloud Episode Annotation
      • Volumes Annotation
    • Python SDK tutorials
      • Images
        • Images
        • Image and object tags
        • Spatial labels on images
        • Keypoints (skeletons)
        • Multispectral images
        • Multiview images
        • Advanced: Optimized Import
        • Advanced: Export
      • Videos
        • Videos
        • Video and object tags
        • Spatial labels on videos
      • Point Clouds
        • Point Clouds (LiDAR)
        • Point Cloud Episodes and object tags
        • 3D point cloud object segmentation based on sensor fusion and 2D mask guidance
        • 3D segmentation masks projection on 2D photo context image
      • Volumes
        • Volumes (DICOM)
        • Spatial labels on volumes
      • Common
        • Iterate over a project
        • Iterate over a local project
        • Progress Bar tqdm
        • Cloning projects for development
    • Command Line Interface (CLI)
      • Enterprise CLI Tool
        • Instance administration
        • Workflow automation
      • Supervisely SDK CLI
    • Connect your computer
      • Linux
      • Windows WSL
      • Troubleshooting
  • 🔥App development
    • Basics
      • Create app from any py-script
      • Configuration file
        • config.json
        • Example 1. Headless
        • Example 2. App with GUI
        • v1 - Legacy
          • Example 1. v1 Modal Window
          • Example 2. v1 app with GUI
      • Add private app
      • Add public app
      • App Compatibility
    • Apps with GUI
      • Hello World!
      • App in the Image Labeling Tool
      • App in the Video Labeling Tool
      • In-browser app in the Labeling Tool
    • Custom import app
      • Overview
      • From template - simple
      • From scratch - simple
      • From scratch GUI - advanced
      • Finding directories with specific markers
    • Custom export app
      • Overview
      • From template - simple
      • From scratch - advanced
    • Neural Network integration
      • Overview
      • Serving App
        • Introduction
        • Instance segmentation
        • Object detection
        • Semantic segmentation
        • Pose estimation
        • Point tracking
        • Object tracking
        • Mask tracking
        • Image matting
        • How to customize model inference
        • Example: Custom model inference with probability maps
      • Serving App with GUI
        • Introduction
        • How to use default GUI template
        • Default GUI template customization
        • How to create custom user interface
      • Inference API
      • Training App
        • Overview
        • Tensorboard template
        • Object detection
      • High level scheme
      • Custom inference pipeline
      • Train and predict automation model pipeline
    • Advanced
      • Advanced debugging
      • How to make your own widget
      • Tutorial - App Engine v1
        • Chapter 1 Headless
          • Part 1 — Hello world! [From your Python script to Supervisely APP]
          • Part 2 — Errors handling [Catching all bugs]
          • Part 3 — Site Packages [Customize your app]
          • Part 4 — SDK Preview [Lemons counter app]
          • Part 5 — Integrate custom tracker into Videos Annotator tool [OpenCV Tracker]
        • Chapter 2 Modal Window
          • Part 1 — Modal window [What is it?]
          • Part 2 — States and Widgets [Customize modal window]
        • Chapter 3 UI
          • Part 1 — While True Script [It's all what you need]
          • Part 2 — UI Rendering [Simplest UI Application]
          • Part 3 — APP Handlers [Handle Events and Errors]
          • Part 4 — State and Data [Mutable Fields]
          • Part 5 — Styling your app [Customizing the UI]
        • Chapter 4 Additionals
          • Part 1 — Remote Developing with PyCharm [Docker SSH Server]
      • Custom Configuration
        • Fixing SSL Certificate Errors in Supervisely
        • Fixing 400 HTTP errors when using HTTP instead of HTTPS
      • Autostart
      • Coordinate System
      • MLOps Workflow integration
    • Widgets
      • Input
        • Input
        • InputNumber
        • InputTag
        • BindedInputNumber
        • DatePicker
        • DateTimePicker
        • ColorPicker
        • TimePicker
        • ClassesMapping
        • ClassesColorMapping
      • Controls
        • Button
        • Checkbox
        • RadioGroup
        • Switch
        • Slider
        • TrainValSplits
        • FileStorageUpload
        • Timeline
        • Pagination
      • Text Elements
        • Text
        • TextArea
        • Editor
        • Copy to Clipboard
        • Markdown
        • Tooltip
        • ElementTag
        • ElementTagsList
      • Media
        • Image
        • LabeledImage
        • GridGallery
        • Video
        • VideoPlayer
        • ImagePairSequence
        • Icons
        • ObjectClassView
        • ObjectClassesList
        • ImageSlider
        • Carousel
        • TagMetaView
        • TagMetasList
        • ImageAnnotationPreview
        • ClassesMappingPreview
        • ClassesListPreview
        • TagsListPreview
        • MembersListPreview
      • Selection
        • Select
        • SelectTeam
        • SelectWorkspace
        • SelectProject
        • SelectDataset
        • SelectItem
        • SelectTagMeta
        • SelectAppSession
        • SelectString
        • Transfer
        • DestinationProject
        • TeamFilesSelector
        • FileViewer
        • Dropdown
        • Cascader
        • ClassesListSelector
        • TagsListSelector
        • MembersListSelector
        • TreeSelect
        • SelectCudaDevice
      • Thumbnails
        • ProjectThumbnail
        • DatasetThumbnail
        • VideoThumbnail
        • FolderThumbnail
        • FileThumbnail
      • Status Elements
        • Progress
        • NotificationBox
        • DoneLabel
        • DialogMessage
        • TaskLogs
        • Badge
        • ModelInfo
        • Rate
        • CircleProgress
      • Layouts and Containers
        • Card
        • Container
        • Empty
        • Field
        • Flexbox
        • Grid
        • Menu
        • OneOf
        • Sidebar
        • Stepper
        • RadioTabs
        • Tabs
        • TabsDynamic
        • ReloadableArea
        • Collapse
        • Dialog
        • IFrame
      • Tables
        • Table
        • ClassicTable
        • RadioTable
        • ClassesTable
        • RandomSplitsTable
        • FastTable
      • Charts and Plots
        • LineChart
        • GridChart
        • HeatmapChart
        • ApexChart
        • ConfusionMatrix
        • LinePlot
        • GridPlot
        • ScatterChart
        • TreemapChart
        • PieChart
      • Compare Data
        • MatchDatasets
        • MatchTagMetas
        • MatchObjClasses
        • ClassBalance
        • CompareAnnotations
      • Widgets demos on github
  • 😎Advanced user guide
    • Objects binding
    • Automate with Python SDK & API
      • Start and stop app
      • User management
      • Labeling Jobs
  • 🖥️UI widgets
    • Element UI library
    • Supervisely UI widgets
    • Apexcharts - modern & interactive charts
    • Plotly graphing library
  • 📚API References
    • REST API Reference
    • Python SDK Reference
Powered by GitBook
On this page
  • 1. Demo project
  • 2. Download project in Supervisely format
  • 3. Python script

Was this helpful?

Edit on GitHub
  1. Getting Started
  2. Python SDK tutorials
  3. Common

Iterate over a local project

PreviousIterate over a projectNextProgress Bar tqdm

Last updated 7 months ago

Was this helpful?

In this article, we will learn how to iterate through a project in , which is stored locally on your machine. It is one of the most frequent operations in Superviely Apps and python automation scripts. You will see how easy it is to get all the necessary information from the project, as well as how quickly you can visualize the contents of the project even without internet access.

Everything you need to reproduce : source code, Visual Studio code configuration, and a shell script for creating venv.

In this guide we will go through the following steps:

**** Get a with labeled lemons and kiwis.

**** Download the demo project to your local machine in Supervisely format using app in Supervisely Ecosystem.

**** Run .

1. Demo project

If you don't have any projects in Supervisely format on your local machine, go to the ecosystem and add the demo project 🍋 Lemons annotated to your current workspace.

Add demo project "Lemons annotated" to your workjspace

2. Download project in Supervisely format

Extract the archive to any folder and check that it has the following structure:

. 📦 (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.json

The project root directory contains the meta.json file with the project meta information and directories for each dataset. Each dataset directory contains two subdirectories: img with images and ann with annotations in Supervisely format.

3. Python script

To start debugging you need to:

Source code:

import 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)

Output

The script above produces the following output:

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'

As a result of running the script there also will be created a directory results, which will contain the images with drawn annotations.

Go to the ecosystem and launch the app . Select the demo project, you created in the previous step (or use any existing project in Supervisely), and download the result archive to your local machine.

Run Export to Supervisely format app
Download the result archive

Clone the

Create by running the script

Set the correct path to the downloaded and extracted project on your local machine in the script

Result images with drawn annotations
🎉
Export to Supervisely format
repo
venv
create_venv.sh
main.py
Supervisely format
this tutorial is on GitHub
Step 1.
demo project
Step 2.
Export to Supervisely format
Step 3.
python script