-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathplot.py
More file actions
93 lines (79 loc) · 3.3 KB
/
Copy pathplot.py
File metadata and controls
93 lines (79 loc) · 3.3 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import sys
import os
import matplotlib.pyplot as plt
import numpy as np
def read_metrics(file_path):
if(os.stat(file_path).st_size == 0):
return []
data = {}
with open(file_path, 'r') as f:
for line in f:
x, y = map(float, line.split(':'))
data[int(x)] = y
max_index = max(data.keys())
array = np.zeros(max_index + 1)
for x, y in data.items():
array[x] = y
return array
def plot(data_file_path, saving_file_path):
base_name = os.path.splitext(os.path.basename(data_file_path))[0]
data = read_metrics(data_file_path)
if len(data) == 0:
return
plt.figure(figsize=(20, 6))
mean_val = np.mean(data)
max_val = np.max(data)
max_label_text = f'Max: {max_val:.2f}'
mean_label_text = f'Mean: {mean_val:.2f}'
plt.plot(data, c = 'b', label=max_label_text)
plt.axhline(y=mean_val, color='g', linestyle='--', label=mean_label_text)
plt.xlabel("frameId")
plt.ylabel("time (ms)")
plt.title(base_name)
plt.grid(True)
plt.legend(loc='upper right')
plt.savefig(saving_file_path, bbox_inches='tight')
plt.close()
if __name__ == "__main__":
if len(sys.argv)-1 != 1:
print(f"Usage: {sys.argv[0]} <stats_dir>")
sys.exit(1)
stats_dir = sys.argv[1]
data_dir = stats_dir + '/data'
SLP_dir = stats_dir + '/data/SearchLocalPointsKernel'
PE_dir = stats_dir + '/data/PoseEstimationKernel'
SM_dir = stats_dir + '/data/StereoMatchKernel'
plot_dir = stats_dir + '/plots'
SLP_plot_dir = stats_dir + '/plots/SearchLocalPointsKernel/'
PE_plot_dir = stats_dir + '/plots/PoseEstimationKernel/'
SM_plot_dir = stats_dir + '/plots/StereoMatchKernel/'
os.makedirs(plot_dir, exist_ok=True)
os.makedirs(SLP_plot_dir, exist_ok=True)
os.makedirs(PE_plot_dir, exist_ok=True)
os.makedirs(SM_plot_dir, exist_ok=True)
for filename in os.listdir(data_dir):
if filename.endswith('.txt'):
if (filename == 'num_frames_lost.txt'): continue
if (filename == 'kernel_initialization_time.txt'): continue
data_file_path = os.path.join(data_dir, filename)
relative_path = os.path.relpath(data_file_path, data_dir)
plot_file_path = os.path.join(plot_dir, filename[:-4] + '.png')
plot(data_file_path, plot_file_path)
for filename in os.listdir(SLP_dir):
if filename.endswith('.txt'):
data_file_path = os.path.join(SLP_dir, filename)
relative_path = os.path.relpath(data_file_path, SLP_dir)
plot_file_path = os.path.join(SLP_plot_dir, filename[:-4] + '.png')
plot(data_file_path, plot_file_path)
for filename in os.listdir(PE_dir):
if filename.endswith('.txt'):
data_file_path = os.path.join(PE_dir, filename)
relative_path = os.path.relpath(data_file_path, PE_dir)
plot_file_path = os.path.join(PE_plot_dir, filename[:-4] + '.png')
plot(data_file_path, plot_file_path)
for filename in os.listdir(SM_dir):
if filename.endswith('.txt'):
data_file_path = os.path.join(SM_dir, filename)
relative_path = os.path.relpath(data_file_path, SM_dir)
plot_file_path = os.path.join(SM_plot_dir, filename[:-4] + '.png')
plot(data_file_path, plot_file_path)