forked from ultralytics/yolov5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exp_960_speed.py
113 lines (98 loc) · 4.46 KB
/
exp_960_speed.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import pandas
from detect import run
from datetime import datetime
import pandas as pd
from pathlib import Path
MODELS = ["yolov5n", "yolov5s", "yolov5m", "yolov5l",
"yolov5n6", "yolov5s6", "yolov5m6", "yolov5l6"]
PRECISION = ["fp16"]
MODEL_TYPES = ["torch", "onnx", "openvino", "openvino_cpu"]
def run_exp_960_speed(models, precisions, model_types):
column_names = ["model_type", "model", "precision", "prep_time", "NMS_time", "latency", "inference_time",
"total_time",
"FPS", "experiment_time", "detection_time"]
map_fps = pd.DataFrame(columns=column_names)
counter = 0
aggr_processing_times = []
for model_type in model_types:
for model in models:
imgsize = 960
for precision in precisions:
if precision == 'int8' and model == 'yolov5l6':
break
row = [f'{model_type}', model, precision]
start_experiment = datetime.now()
if model_type == 'openvino' or 'openvino_cpu':
model_path = Path(f'./openvino_models/{model}_{imgsize}_{precision}')
elif model_type == 'onnx':
model_path = Path(f'./onnx_models/{model}_{imgsize}.onnx')
elif model_type == 'torch':
model_path = f'{model}.pt'
else:
print('Not a valid model type')
break
if model_type == 'openvino_cpu':
openvino_device = 'CPU'
print(row)
temp, processing_times = run(
weights=model_path,
source="../datasets/coco/images/val2017/000000000139.jpg", # /datasets/coco128/images/train2017/
nosave=True,
imgsz=(imgsize, imgsize),
openvino_device=openvino_device
)
else:
temp, processing_times = run(
weights=model_path,
source="../datasets/coco/images/val2017/000000000139.jpg", # /datasets/coco128/images/train2017/
nosave=True,
imgsz=(imgsize, imgsize),
)
aggr_processing_times.extend(processing_times[0])
# create row for map_fps data
row.append(temp[0]) # preprocessing
row.append(temp[2]) # NMS
row.append(temp[0] + temp[2]) # latency (prep + NMS)
row.append(temp[1]) # inference
row.append(sum(temp)) # total time
row.append(1 / (sum(temp)) * 1E3) # FPS
row.append((datetime.now() - start_experiment).seconds) # duration of experiment
row.append(processing_times[1])
map_fps.loc[counter] = row
counter += 1
# store inference times of all images per model
filename = Path(
f'results/experiments/exp_960_fps/{datetime.now().strftime("%y%m%d-%H-%M")}_processing_times')
filename.parent.mkdir(parents=True, exist_ok=True)
df_aggr_processing_times = pd.DataFrame(aggr_processing_times,
columns=['model_ext', 'model', 'path_dets', 'prep_time', 'normalize',
'inference', 'nms'])
df_aggr_processing_times.round(3)
df_aggr_processing_times.to_csv(str(filename) + '.csv')
# store mAP results
filename = Path(f'results/experiments/exp_960_fps/{datetime.now().strftime("%y%m%d-%H-%M")}_exp_time')
filename.parent.mkdir(parents=True, exist_ok=True)
map_fps.round(3)
# x.to_pickle(str(filename) + '.pkl')
map_fps.to_csv(str(filename) + '.csv')
# #%%
# import os
#
# path = './onnx_models/yolov5l6_640.onnx'
# split = os.path.split(path)
# model = os.path.splitext(split[1])[0]
# model_extension = os.path.splitext(split[1])[1].replace('.', '')
# print(f'model:'
# f' {model} model_extension: {model_extension}')
#
# import pandas as pd
#
# file = pd.read_pickle(
# "./results/experiments/exp_960_speed/220623-Jun-06_speed.pkl")
# file.to_csv("./results/experiments/exp_960_speed/220623-Jun-06_speed.csv")
# #%%
if __name__ == "__main__":
run_exp_960_speed(['yolov5n'], ['fp16'], ['openvino', 'openvino_cpu'])
# run_exp_960_speed(MODELS, ['fp32'], MODEL_TYPES)
#run_exp_960_speed(MODELS, ['fp32', 'fp16', 'int8'], ['openvino'])
#