forked from JIAOJIAYUASD/dilateformer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_tensorboard.py
28 lines (26 loc) · 1.15 KB
/
generate_tensorboard.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
import os
import json
from tensorboardX import SummaryWriter
exp_path_list = ['exp']
log_keys = ['train_lr', 'train_loss', 'test_loss', 'test_acc1', 'test_acc5']
ignore_exp = []
for path in exp_path_list:
for exp in os.listdir(path):
log_path = os.path.join('.', path, exp, 'ckpt', 'log.txt')
if os.path.exists(log_path):
tensorboard_path = os.path.join('.', path, exp, 'events')
if os.path.exists(tensorboard_path):
for old_exp in os.listdir(tensorboard_path):
delete_path = os.path.join(tensorboard_path, old_exp)
print('delete:', delete_path)
os.remove(delete_path)
tb_logger = SummaryWriter(tensorboard_path)
if exp not in ignore_exp:
with open(log_path, 'r') as f:
lines = f.readlines()
for line in lines:
log = json.loads(line.rstrip())
for k in log_keys:
tb_logger.add_scalar(k, log[k], log['epoch'])
print("load ok in:", tensorboard_path)
tb_logger.close()