forked from Niche-Lab/COLO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_5_inference_time.py
97 lines (77 loc) · 2.05 KB
/
_5_inference_time.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
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
import numpy as np
import pandas as pd
import re
import os
import seaborn as sns
FILE_OUT = os.path.join("out", "b0313", "fig5_inference.png")
def find_init(lines):
s = []
for line in lines:
s += [re.search(r"Ultralytics YOLOv8", line)]
return np.where(s)[0]
def find_model(s):
find = re.findall(r"YOLOv\d.", s)[0]
return str(find)
def find_device(s):
return "CPU" if "CPU" in s else "GPU"
def find_ms(s):
ms_str = re.findall(r"\d+\.\d+ms", s)[0]
return float(ms_str[:-2])
lines = open("data/mock/log.txt").readlines()
idx_init = find_init(lines)
idx_model = idx_init + 1
idx_iter_st = idx_init + 3
idx_iter_ed = idx_init + 3 + 64
data = pd.DataFrame(data=None)
for i in range(len(idx_init)):
str_model = lines[idx_model[i]]
str_device = lines[idx_init[i]]
idx_st = idx_iter_st[i]
idx_ed = idx_iter_ed[i]
model = find_model(str_model)
device = find_device(str_device)
ms = []
for j in range(idx_st, idx_ed):
ms += [find_ms(lines[j])]
data_tmp = pd.DataFrame(data=dict({"model": model, "device": device, "ms": ms}))
data = pd.concat([data, data_tmp])
# turn model to string
data["fps"] = 1000 / data["ms"]
data["yolo"] = data["model"].apply(lambda x: "v8" if "8" in x else "v9")
df_param = pd.DataFrame(
data={
"model": ["YOLOv8n", "YOLOv9c", "YOLOv8m", "YOLOv9e", "YOLOv8x"],
"size": [3.2, 25.3, 25.9, 57.3, 68.2],
}
)
data = pd.merge(data, df_param, how="left")
sns.set_style("whitegrid")
g = sns.FacetGrid(
data,
col="device",
col_order=["CPU", "GPU"],
col_wrap=2,
margin_titles=True,
sharey=False,
)
g.map_dataframe(
sns.lineplot,
x="size",
y="fps",
hue="yolo",
style="yolo",
hue_order=["v8", "v9"],
style_order=["v8", "v9"],
err_style="band",
errorbar=("se", 2),
markers=True,
palette=["Grey", "#FF1F5B"],
)
g.set(
ylabel="FPS",
xlabel="Number of Model Parameters (M)",
)
g.figure.subplots_adjust(right=1.2)
g.add_legend()
g.figure.set_size_inches(8, 4)
g.figure.savefig(FILE_OUT, dpi=300)