In this tutorial we will show you how to use 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 : source code.
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/tutorial-tqdm.git
cd tutorial-tqdm
./create_venv.sh
Step 3. Open repository directory in Visual Studio Code.
code .
Step 4. Change project ID in local.env file by copying the ID from the context menu of the workspace.
PROJECT_ID=17732 # ⬅️ change value
TEAM=449 # ⬅️ change value
Step 5. Start debugging src/main.py.
Import libraries
import os
import time
from dotenv import load_dotenv
import supervisely as sly
from tqdm import tqdm
Init API client
First, we load environment variables with credentials and init API for communicating with Supervisely Instance.
if sly.is_development():
load_dotenv("local.env")
load_dotenv(os.path.expanduser("~/supervisely.env"))
api = sly.Api()
batch_size = 10
data = range(100)
with tqdm(total=len(data)) as pbar:
for batch in sly.batched(data, batch_size):
for item in batch:
time.sleep(0.1)
pbar.update(batch_size)
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
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.
In this tutorial, you will need an workspace ID that you can get from environment variables.
Example 1a
Example 1b
This is how progress bar might look like in the Workspace Tasks