用法1:
代码:
from tqdm import tqdm
import time
for i in tqdm(range(100)):
time.sleep(0.01)
结果:

用法2
代码:
from tqdm import trange
epoch = 10
n_batches = 10000
with tqdm(total=n_batches, desc='Train epoch %d' % epoch) as train_enum:
for batch_num in range(n_batches):
batch_loss = 3.25
train_enum.set_description(f'Train (loss: {batch_loss:.2f}) epoch {epoch}')
train_enum.update()
结果:

参考链接
python的Tqdm模块
https://github.com/tqdm/tqdm/tree/master/examples
https://pypi.python.org/pypi/tqdm
https://github.com/tqdm/tqdm
本文详细介绍了Python中Tqdm模块的两种常见用法,包括如何在循环中显示进度条以及如何在训练过程中实时更新损失值,使数据处理过程更加直观。Tqdm模块能够有效提升代码的可读性和用户体验。
394

被折叠的 条评论
为什么被折叠?



