-
Notifications
You must be signed in to change notification settings - Fork 0
/
double_tqdm_demo.py
65 lines (43 loc) · 1.5 KB
/
double_tqdm_demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from tqdm import tqdm
import time
def demo1():
outer_loop = range(10)
inner_loop = range(5)
for i in tqdm(outer_loop,desc="outer_loop",position=0,ncols=160,leave=True): # leave means NOT disappear
for j in tqdm(inner_loop,desc="inner_loop",position=1,ncols=150,leave=False): # leave=False means disappear=True
time.sleep(0.5)
def demo2():
epochs = 5
len_loader = 10
total_step = epochs * len_loader
pbar_global = tqdm(total=total_step,desc="global iter", position=0, leave=True)
pbar_local = tqdm(total=len_loader,desc="per epoch iter", position=1, leave=False)
done_epochs = 0
for it in range(total_step):
time.sleep(0.5)
pbar_global.update()
pbar_local.update()
if (it+1) % len_loader == 0:
done_epochs +=1
pbar_local.reset()
pbar_global.close()
pbar_local.close()
def demo3():
epochs = 5
len_loader = 10
total_step = epochs * len_loader
pbar_global = tqdm(total=epochs,desc="global epochs", position=0, leave=True)
pbar_local = tqdm(total=len_loader,desc="per epoch iter", position=1, leave=True)
done_epochs = 0
for it in range(total_step):
time.sleep(0.5)
pbar_local.update()
if (it+1) % len_loader == 0:
done_epochs +=1
pbar_global.update()
pbar_local.reset()
pbar_global.close()
pbar_local.close()
if __name__ == "__main__":
# demo1()
demo3()