Om Fuke
Om Fuke

Reputation: 662

best way of tqdm for data loader

How to use tqdm for data_loader ?

is this the correct way?

for i,j in enumerate(data_loader,total = 100):
           pass

Upvotes: 27

Views: 49513

Answers (3)

You can do it like this:


    for Step, Data in tqdm(enumerate(data_loader), total= len(data_loader), desc="Processing data"):
         //Process data

This will print the percentage, and the fraction step/total staps

Upvotes: 0

Hamzah Al-Qadasi
Hamzah Al-Qadasi

Reputation: 9806

If you want to use enumerate with tqdm, you can use it this way:

for i,data in enumerate(tqdm(train_dataloader)):
    images, labels = data 
    images, labels = images.to(device), labels.to(device)
    ....

Upvotes: 5

Bitswazsky
Bitswazsky

Reputation: 4698

You need to wrap the iterable with tqdm, as their documentation clearly says:

Instantly make your loops show a smart progress meter - just wrap any iterable with tqdm(iterable), and you’re done!

If you're enumerating over an iterable, you can do something like the following. Sleep is only for visualizing it.

from tqdm import tqdm
from time import sleep

data_loader = list(range(1000))

for i, j in enumerate(tqdm(data_loader)):
    sleep(0.01)

Upvotes: 34

Related Questions