1使用原因
使用Python處理比較耗時的操作泼返,為了便于觀察處理進度,這時需要通過進度條將處理情況進行可視化展示。
2 安裝
pip install tqdm
3 簡單使用
# -*- coding: utf-8 -*-
from tqdm import tqdm
from collections import OrderedDict
total = 100000 # 總迭代次數(shù)
loss = total
with tqdm(total=total, desc="進度條") as pbar:
for i in range(total):
loss -= 1
# 下面?zhèn)€兩行功能一樣
# pbar.set_postfix(OrderedDict(loss='{0:1.5f}'.format(loss)))
pbar.set_postfix({'loss': '{0:1.5f}'.format(loss)}) # 輸入一個字典,顯示實驗指標
pbar.update(1)
運行結(jié)束時輸出:
進度條: 100%|██████████| 100000/100000 [00:05<00:00, 16960.72it/s, loss=0.00000]
4 感謝鏈接
https://blog.csdn.net/A_A666/article/details/110851037