注: f"{}" 的说明:
eg1:
from tqdm import tqdm
import time
epoch_size=100
Epoch=1000
epoch=45
with tqdm(total=epoch_size, desc=f'Epoch {epoch + 1}/{Epoch}', postfix=dict, mininterval=0.01) as pbar:
for i in range(10):
time.sleep(0.5)
tqdm(total=epoch_size, desc=f'Epoch {epoch + 1}/{Epoch}', postfix=dict,mininterval=1)
pbar.update(1)
eg2:
eg3:
附:
from tqdm import tqdm, trange
from random import random, randint
from time import sleep
#trange 是tqdm(range)的简用方式:
for i in trange(int(1e8)):
pass
for i in trange(int(1e8),miniters = int(1e6),ascii= True,desc ='bar',colour = 'blue',mininterval = 0.5):
pass
with trange(10) as t:
for i in t:
# Description will be displayed on the left
t.set_description('GEN %i' % i)
# Postfix will be displayed on the right,
# formatted automatically based on argument's datatype
t.set_postfix(loss=random(), gen=randint(1,999), str='h',
lst=[1, 2])
sleep(0.1)
with tqdm(total=10, bar_format="{postfix[0]} {postfix[1][value]:>8.2g}",
postfix=["Batch", dict(value=0)]) as t:
for i in range(10):
sleep(0.1)
t.postfix[1]["value"] = i / 2
t.update()