I'm using the tqdm library and it doesn't give me the progress bar, instead it gives me output that looks like this where it just tells me the iteration:
251it [01:44, 2.39it/s]
Any idea why the code would do this? I thought it was maybe because I was passing it a generator but then again I've used generators in the past that have worked. I've never really messed with tdqm formatting before. Here is part of the source code:
train_iter = zip(train_x, train_y) #train_x and train_y are just lists of elements .... def train(train_iter, model, criterion, optimizer): model.train() total_loss = 0 for x, y in tqdm(train_iter): x = x.transpose(0, 1) y = y.transpose(0, 1) optimizer.zero_grad() bloss = model.forward(x, y, criterion) bloss.backward() torch.nn.utils.clip_grad_norm(model.parameters(), args.clip) optimizer.step() total_loss += bloss.data[0] return total_loss
tqdm is a Python library that provides functions that wrap around the specified iterable to give a smart progress bar as an output. Python is a widely-used language to perform computationally intensive tasks that run over longer periods. A tqdm progress bar gives an indicator of the progress of these tasks.
tqdm works on any platform (Linux, Windows, Mac, FreeBSD, NetBSD, Solaris/SunOS), in any console or in a GUI, and is also friendly with IPython/Jupyter notebooks.
There is a disable argument which you can set to True to silence any tqdm output (and in fact it will totally skip the progress bar calculations too, not just the display). To dynamically switch it, you can just add a commandline argument to your script that will define if disable is set or not.
Hence you have some problem with your iterable or loop code, not with tqdm. Possible reason could be that your inner loop takes to long time so even 1 iteration (out of total 6986 in your case) takes forever and is not showed in progress bar.
If you’re familiar with Arabic, then you may have noticed that the pronunciation of tqdm sounds like the Arabic word that means progress, ( taqadum, تقدّم). Thus, it’s definitely a befitting name for this progress bar library. Let’s see how we can use tqdm to display progress bars for our Python loops. First, we need to install tqdm.
So it means tqdm works in notebook mode correctly. Hence you have some problem with your iterable or loop code, not with tqdm. Possible reason could be that your inner loop takes to long time so even 1 iteration (out of total 6986 in your case) takes forever and is not showed in progress bar.
There are multiple parameters in a tqdm; let us understand them one by one. Parameters in Python Tqdm Iterable– It can be a range, a list whose progress we have to check. Example-
tqdm
needs to known how many iters will be performed (the total amount) to show a progress bar.
You can try this:
from tqdm import tqdm train_x = range(100) train_y = range(200) train_iter = zip(train_x, train_y) # Notice `train_iter` can only be iter over once, so i get `total` in this way. total = min(len(train_x), len(train_y)) with tqdm(total=total) as pbar: for item in train_iter: # do something ... pbar.update(1)
Filling the "total" parameter with length worked for me. Now the progress bar appears.
from tqdm import tqdm # ... for imgs, targets in tqdm( train_dataloader, total=len(train_dataloader)): # ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With