-
Notifications
You must be signed in to change notification settings - Fork 3
/
util_txt_2_csv.py
64 lines (58 loc) · 1.59 KB
/
util_txt_2_csv.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
import os
COLUMNS = [
'global_step',
'accuracy',
'accuracy_baseline',
'auc',
'auc_precision_recall',
'loss',
'average_loss',
'label/mean',
'prediction/mean',
'train_time',
'test_time',
]
SEPARATOR = ','
def txt_2_csv(INPUT_FILE, OUTPUT_FILE):
input_file = open(INPUT_FILE)
output_file = open(OUTPUT_FILE, 'w')
index = 1
line = input_file.readline()
while line:
# line=line.strip()
# print(index, "=", line)
infos = {}
pairs = line.split(',')
for pair in pairs:
key, value = pair.split('=')
infos[key.strip()] = value.strip()
# print(infos)
if index == 1:
output_file.write(SEPARATOR.join(COLUMNS)+'\n')
values = list(map(lambda x:infos[x], COLUMNS))
output_file.write(SEPARATOR.join(values)+'\n')
# output_file.write(line+'\n')
index = index + 1
line = input_file.readline()
input_file.close()
output_file.close()
pass
def main():
model_dir = './model'
if not os.path.exists(model_dir):
return
dirs = os.listdir(model_dir)
for dir in dirs:
file_path = '{model_dir}/{dir}'.format(model_dir=model_dir, dir=dir)
# print(file_path)
tmp_path, tmp_ext = os.path.splitext(file_path)
if tmp_ext == '.txt':
new_path = '{file}.csv'.format(file=tmp_path)
# print(new_path)
txt_2_csv(file_path, new_path)
pass
if __name__ == "__main__":
# main()
from sys import argv
_, input, output = argv
txt_2_csv(input, output)