Progress Bar tqdm
Introduction
In this tutorial we will show you how to use tqdm module inside methods of Supervisely SDK in a seamless manner.
🔥 With this update, any sly.Progress object can be easily replaced with tqdm, allowing you to seamlessly integrate your progress tracking with the powerful features of tqdm. Say goodbye to headaches!
📗 Everything you need to reproduce this tutorial is on GitHub: source code.
How to debug this tutorial
Step 1. Prepare ~/supervisely.env
file with credentials. Learn more here.
Step 2. Clone repository with source code and demo data and create Virtual Environment.
Step 3. Open repository directory in Visual Studio Code.
Step 4. Change project ID in local.env
file by copying the ID from the context menu of the workspace.
Step 5. Start debugging src/main.py
.
Import libraries
Init API client
First, we load environment variables with credentials and init API for communicating with Supervisely Instance.
Get variables from environment
In this tutorial, you will need an workspace ID that you can get from environment variables. Learn more here
Use tqdm for tracking progress
Example 1. Use tqdm in the loop.
Source code:
Output:
When running locally, the fancy-looking tqdm progress bar will be displayed in the console, while in production, JSON-looking lines with relevant information will be logged and fancy-looking progress bar will be shown in Workspace Tasks.
Example 2. Download image project and upload it into Team files using tqdm progress bar.
Source code:
Download your project with previously initiialized project_id
Output:
Then, you can upload downloaded directory to Team files:
Source code:
Output:
Example 3 (advanced). Use native sly.Progress functions for downloading.
Let's reproduce previous example with Supervisely's native Progress bar.
Source code:
Output:
You will get files in progress.
Then, you can upload downloaded directory to Team files:
Source code:
Output:
You can swap equivalent arguments from sly.Progress
while initializing tqdm
. For example, the desc
argument can be replaced with message
, and total
can be replaced with total_cnt
. Additionally, both unit="B"
and unit_scale=True
can be replaced with is_size=True
.
Last updated