1使用原因
使用Python处理比较耗时的操作,为了便于观察处理进度,这时需要通过进度条将处理情况进行可视化展示。
2 安装
pip install tqdm
3 简单使用
# -*- coding: utf-8 -*-
from tqdm import tqdm
from collections import OrderedDict
total = 100000 # 总迭代次数
loss = total
with tqdm(total=total, desc="进度条") as pbar:
for i in range(total):
loss -= 1
# 下面个两行功能一样
# pbar.set_postfix(OrderedDict(loss='{0:1.5f}'.format(loss)))
pbar.set_postfix({'loss': '{0:1.5f}'.format(loss)}) # 输入一个字典,显示实验指标
pbar.update(1)
运行结束时输出:
进度条: 100%|██████████| 100000/100000 [00:05<00:00, 16960.72it/s, loss=0.00000]
4 感谢链接
https://blog.csdn.net/A_A666/article/details/110851037