-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_pkl.py
72 lines (54 loc) · 2.1 KB
/
read_pkl.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
66
67
68
69
70
71
72
import pickle as pkl
import pandas as pd
import os
def read_pkl(path):
with open(path, 'rb') as f:
data = pkl.load(f)
return data
def read_txt(path):
with open(path, 'r') as f:
data = f.readlines()
return data
def parse_eval(path):
with open(path, 'r') as f:
data = f.readlines()
info_line = []
flag_info = False
for i, info in enumerate(data):
if "INFO Car [email protected], 0.70, 0.70:" in info:
info_line.append(i)
flag_info = True
if flag_info:
if not "AP" in info:
flag_info = False
else:
info_line.append(i)
valid_info = data[info_line[0]:info_line[-1]+1]
valid_info[0] = valid_info[0][32:]
return valid_info
def save_data(path, data):
"""保存数据到excel文件"""
data = [i.split() for i in data]
# 每5行增加空行
# 在每五行之后插入一行空白行
for i in range(1, len(data) // 5 + 1):
data.insert(i * 6 - 1, [None, None, None])
df = pd.DataFrame(data)
#将path路径的.txt改为.xlsx
excel_file = path.replace('.txt', '.xlsx')
# 将DataFrame保存到Excel文件
df.to_excel(excel_file, index=False)
print(f'Data has been saved to {excel_file}.')
if __name__ == '__main__':
# path = r'/home/dell/workspace/motion/cd/output/cfgs/kitti_models/pillarnet_img/default/eval/epoch_80/val/default/result.pkl'
# data = read_pkl(path)
# print(data)
# path = r'output/cfgs/kitti_models/centerpoint_img_paper2/default/eval/epoch_80/val/default/log_eval_20240429-151734.txt'
# data = parse_eval(path)
# save_data(path, data)
for filename in os.listdir('output/cfgs/kitti_models/centerpoint_img_paper2/default/eval/epoch_80/val/default/'):
if filename.startswith('log_eval_20240429') and filename.endswith('.txt'):
path = os.path.join('output/cfgs/kitti_models/centerpoint_img_paper2/default/eval/epoch_80/val/default/', filename)
data = parse_eval(path)
save_data(path, data)
print(f'{filename} has been processed.')