0%

Tqdm 实时显示 Loss 和 Acc

代码示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from random import random
from time import sleep
from tqdm import tqdm

epochs = 2
train_data_num = 10
for i in range(epochs):
with tqdm(total=train_data_num) as t:
for j in range(10):
# Description will be displayed on the left
t.set_description('Epoch %i' % i)
# Postfix will be displayed on the right,
# formatted automatically based on argument's datatype
t.set_postfix(loss=random(),acc=random())
sleep(0.1)
t.update(1)

输出结果:

1
2
Epoch 0: 100%|██████████| 10/10 [00:01<00:00,  9.94it/s, acc=0.0863, loss=0.999]
Epoch 1: 100%|██████████| 10/10 [00:01<00:00, 9.93it/s, acc=0.459, loss=0.921]

支持一根棒棒糖!