-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrate.py
More file actions
173 lines (140 loc) · 5.21 KB
/
rate.py
File metadata and controls
173 lines (140 loc) · 5.21 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import pandas as pd
from scipy.stats import gmean
import re
import os
import argparse
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import numpy as np
import json
parser = argparse.ArgumentParser(description="Process OpenCV performance results.")
parser.add_argument(
"--output", default="scores.md",
help="Output scores filename"
)
parser.add_argument(
"--modules", nargs="+",
help="Module Name(s)"
)
parser.add_argument(
"--figure", default=False, action="store_true",
help="Create figure for each module"
)
args = parser.parse_args()
output_file = args.output
# 4.x
modules=["core", "imgproc", "features2d", "objdetect", "calib3d", "dnn"]
# 5.x
#modules=["core", "imgproc", "features", "objdetect", "3d", "calib", "stereo", "dnn"]
if args.modules:
modules = args.modules
df = None
for module in modules:
file_name = f"perf/{module}.html"
if not os.path.exists(file_name):
continue
try:
df = pd.read_html(file_name)[0]
break
except Exception as e:
print(f"Error reading {file_name}: {e}")
continue
if df is None:
print("No valid performance HTML files found.")
exit(1)
rows, cols = df.shape
col_start = cols // 2 + 1
cols_to_calculate = list(range(col_start, cols))
dev_types = [re.search(r'-(.*?)\s+vs', s).group(1) for s in df.columns.tolist()[col_start:]]
result = dict()
result["module"] = []
for dev_type in dev_types:
result[dev_type] = []
for module in modules:
file_name = f"perf/{module}.html"
if not os.path.exists(file_name):
continue
try:
df = pd.read_html(file_name)[0]
except Exception as e:
print(f"Error reading {file_name}: {e}")
continue
df['Group'] = df.iloc[:, 0].astype(str).str.split(':').str[0]
result["module"].append(module)
for col_idx in cols_to_calculate:
col_name = df.columns[col_idx]
df[col_name] = pd.to_numeric(df[col_name], errors='coerce')
valid_df = df.dropna(subset=[col_name])
group_gmeans = valid_df.groupby('Group')[col_name].apply(lambda x: gmean(x[x > 0]) if any(x > 0) else float('nan'))
file_col_gmean = gmean(group_gmeans.dropna()) if not group_gmeans.dropna().empty else float('nan')
result[dev_types[col_idx - col_start]].append(file_col_gmean * 100)
df = pd.DataFrame(result)
mean_scores = df.drop(columns="module").apply(lambda x: gmean(x[x > 0]) if any(x > 0) else float('nan'))
df.loc['Score'] = ['Score'] + mean_scores.tolist()
numeric_cols = df.select_dtypes(include="number").columns
df[numeric_cols] = df[numeric_cols].round(2)
with open(output_file, "w") as f:
f.write(df.to_markdown(index=False))
print(df.to_string(index=False))
# Create figures:
if args.figure:
with open("processor.json", "r", encoding="utf-8") as f:
data = json.load(f)
Baseline = f"{data['baseline']['Processor']}\n{data['baseline']['Cores']}"
Processor = [f"{p['Processor']} | {p['Cores']} | {p['Arch']}" for p in data["processors"]]
devices = [c for c in df.columns if c != "module"]
ARCH_COLORS = {
"ARM": "#7233F7", # purple
"RISC-V": "#EDAC1A", # yellow
"x86_64": "#00C7FD", # cyan
"Unknown": "#A01A1E" # red
}
legend_items = [mpatches.Patch(color="gray", label="Baseline (ARM)")]
for arch, color in ARCH_COLORS.items():
if arch != "Unknown":
legend_items.append(mpatches.Patch(color=color, label=arch))
# legend_items.append(mpatches.Patch(color=ARCH_COLORS["Unknown"], label="Unknown"))
# Loop over each row
for _, row in df.iterrows():
module_name = row["module"]
score_map = dict(zip(devices, row[devices].astype(float)))
labels = []
scores = []
colors = []
labels.append(Baseline)
scores.append(100)
colors.append("gray") # Baseline color
for p in Processor:
soc, cores, arch = [x.strip() for x in p.split("|")]
if soc in score_map:
labels.append(f"{soc}\n{cores}")
scores.append(score_map[soc])
colors.append(ARCH_COLORS.get(arch, ARCH_COLORS["Unknown"]))
plt.figure(figsize=(10, 0.5 * len(labels)))
y_pos = np.arange(len(labels))
bars = plt.barh(y_pos, scores, color=colors)
bars[0].set_color("gray") # Baseline bar in gray
plt.tick_params(axis='y', length=0)
plt.yticks(y_pos, labels, fontweight='bold')
plt.xticks([])
if module_name == "Score":
plt.title("Processor Benchmark", fontweight="bold")
else:
plt.title(module_name, fontweight="bold")
plt.legend(handles=legend_items, loc="upper right", frameon=False)
plt.gca().invert_yaxis()
for spine in plt.gca().spines.values():
spine.set_visible(False)
for bar, score in zip(bars, scores):
plt.text(
bar.get_width(),
bar.get_y() + bar.get_height() / 2,
f" {score:.2f}",
va="center",
ha="left",
fontsize=9
)
plt.tight_layout()
# plt.show()
print(f"Saving figure for {module_name}...")
plt.savefig(f"perf/{module_name}.png")