Spaces:
Sleeping
Sleeping
remove tests
Browse files- tests.py +0 -37
- user-friendly-metrics.py +27 -25
tests.py
DELETED
@@ -1,37 +0,0 @@
|
|
1 |
-
import numpy as np
|
2 |
-
test_cases = [
|
3 |
-
{
|
4 |
-
"predictions": [np.array(a) for a in [
|
5 |
-
[1,1,10,20,30,40,0.85],
|
6 |
-
[1,2,50,60,70,80,0.92],
|
7 |
-
[1,3,80,90,100,110,0.75],
|
8 |
-
[2,1,15,25,35,45,0.78],
|
9 |
-
[2,2,55,65,75,85,0.95],
|
10 |
-
[3,1,20,30,40,50,0.88],
|
11 |
-
[3,2,60,70,80,90,0.82],
|
12 |
-
[4,1,25,35,45,55,0.91],
|
13 |
-
[4,2,65,75,85,95,0.89]
|
14 |
-
]],
|
15 |
-
"references": [np.array(a) for a in [
|
16 |
-
[1, 1, 10, 20, 30, 40],
|
17 |
-
[1, 2, 50, 60, 70, 80],
|
18 |
-
[1, 3, 85, 95, 105, 115],
|
19 |
-
[2, 1, 15, 25, 35, 45],
|
20 |
-
[2, 2, 55, 65, 75, 85],
|
21 |
-
[3, 1, 20, 30, 40, 50],
|
22 |
-
[3, 2, 60, 70, 80, 90],
|
23 |
-
[4, 1, 25, 35, 45, 55],
|
24 |
-
[5, 1, 30, 40, 50, 60],
|
25 |
-
[5, 2, 70, 80, 90, 100]
|
26 |
-
]],
|
27 |
-
"result": {'idf1': 0.8421052631578947, 'idp': 0.8888888888888888,
|
28 |
-
'idr': 0.8, 'recall': 0.8, 'precision': 0.8888888888888888,
|
29 |
-
'num_unique_objects': 3,'mostly_tracked': 2,
|
30 |
-
'partially_tracked': 1, 'mostly_lost': 0,
|
31 |
-
'num_false_positives': 1, 'num_misses': 2,
|
32 |
-
'num_switches': 0, 'num_fragmentations': 0,
|
33 |
-
'mota': 0.7, 'motp': 0.02981870229007634,
|
34 |
-
'num_transfer': 0, 'num_ascend': 0,
|
35 |
-
'num_migrate': 0}
|
36 |
-
},
|
37 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
user-friendly-metrics.py
CHANGED
@@ -169,11 +169,25 @@ def calculate(predictions,
|
|
169 |
|
170 |
return summary
|
171 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
def calculate_from_payload(payload: dict,
|
173 |
max_iou: float = 0.5,
|
174 |
filters = {},
|
175 |
recognition_thresholds = [0.3, 0.5, 0.8],
|
176 |
debug: bool = False):
|
|
|
177 |
if not isinstance(payload, dict):
|
178 |
try:
|
179 |
payload = payload.to_dict()
|
@@ -191,15 +205,7 @@ def calculate_from_payload(payload: dict,
|
|
191 |
print("sequence_list: ", sequence_list)
|
192 |
|
193 |
metrics_per_sequence = {}
|
194 |
-
metrics_global =
|
195 |
-
for model in models:
|
196 |
-
metrics_global[model] = {}
|
197 |
-
metrics_global[model]["all"] = {}
|
198 |
-
for filter, filter_ranges in filters.items():
|
199 |
-
metrics_global[model][filter] = {}
|
200 |
-
for filter_range in filter_ranges:
|
201 |
-
filter_range_name = filter_range[0]
|
202 |
-
metrics_global[model][filter][filter_range_name] = {}
|
203 |
|
204 |
for sequence in sequence_list:
|
205 |
metrics_per_sequence[sequence] = {}
|
@@ -217,14 +223,16 @@ def calculate_from_payload(payload: dict,
|
|
217 |
index = detection['index']
|
218 |
x, y, w, h = detection['bounding_box']
|
219 |
all_formated_references["all"].append([frame_id+1, index, x, y, w, h])
|
|
|
220 |
for filter, filter_ranges in filters.items():
|
221 |
filter_value = detection[filter]
|
222 |
for filter_range in filter_ranges:
|
223 |
-
filter_range_name = filter_range[0]
|
224 |
-
filter_range_limits = filter_range[1]
|
225 |
if filter_value >= filter_range_limits[0] and filter_value <= filter_range_limits[1]:
|
226 |
all_formated_references[filter][filter_range_name].append([frame_id+1, index, x, y, w, h])
|
227 |
|
|
|
|
|
228 |
for model in models:
|
229 |
frames = payload['sequences'][sequence][model]
|
230 |
formated_predictions = []
|
@@ -233,19 +241,20 @@ def calculate_from_payload(payload: dict,
|
|
233 |
for detection in frame:
|
234 |
index = detection['index']
|
235 |
x, y, w, h = detection['bounding_box']
|
236 |
-
confidence =
|
237 |
-
confidence = 1 #TODO: remove this line
|
238 |
formated_predictions.append([frame_id+1, index, x, y, w, h, confidence])
|
|
|
239 |
if debug:
|
240 |
print("sequence/model: ", sequence, model)
|
241 |
print("formated_predictions: ", formated_predictions)
|
242 |
print("formated_references: ", all_formated_references)
|
|
|
243 |
if len(formated_predictions) == 0:
|
244 |
metrics_per_sequence[sequence][model] = "Model had no predictions."
|
245 |
elif len(all_formated_references["all"]) == 0:
|
246 |
metrics_per_sequence[sequence][model] = "No ground truth."
|
|
|
247 |
else:
|
248 |
-
metrics_per_sequence[sequence][model] = {}
|
249 |
|
250 |
sequence_metrics = calculate(formated_predictions, all_formated_references["all"], max_iou=max_iou, recognition_thresholds = recognition_thresholds)
|
251 |
sequence_metrics = realize_metrics(sequence_metrics, recognition_thresholds)
|
@@ -255,7 +264,7 @@ def calculate_from_payload(payload: dict,
|
|
255 |
metrics_global[model]["all"] = realize_metrics(metrics_global[model]["all"], recognition_thresholds)
|
256 |
|
257 |
for filter, filter_ranges in filters.items():
|
258 |
-
|
259 |
for filter_range in filter_ranges:
|
260 |
|
261 |
filter_range_name = filter_range[0]
|
@@ -291,6 +300,9 @@ def sum_dicts(dict1, dict2):
|
|
291 |
|
292 |
def realize_metrics(metrics_dict,
|
293 |
recognition_thresholds):
|
|
|
|
|
|
|
294 |
|
295 |
metrics_dict["precision"] = metrics_dict["tp"]/(metrics_dict["tp"]+metrics_dict["fp"])
|
296 |
metrics_dict["recall"] = metrics_dict["tp"]/(metrics_dict["tp"]+metrics_dict["fn"])
|
@@ -301,13 +313,3 @@ def realize_metrics(metrics_dict,
|
|
301 |
|
302 |
return metrics_dict
|
303 |
|
304 |
-
def per_sequence_to_global(metrics_dict):
|
305 |
-
global_metrics = {}
|
306 |
-
for sequence in metrics_dict:
|
307 |
-
for model in metrics_dict[sequence]:
|
308 |
-
if model not in global_metrics:
|
309 |
-
global_metrics[model] = metrics_dict[sequence][model]
|
310 |
-
else:
|
311 |
-
global_metrics[model] = sum_dicts(global_metrics[model], metrics_dict[sequence][model])
|
312 |
-
|
313 |
-
return global_metrics
|
|
|
169 |
|
170 |
return summary
|
171 |
|
172 |
+
def build_metrics_template(models, filters):
|
173 |
+
metrics_dict = {}
|
174 |
+
for model in models:
|
175 |
+
metrics_dict[model] = {}
|
176 |
+
metrics_dict[model]["all"] = {}
|
177 |
+
for filter, filter_ranges in filters.items():
|
178 |
+
metrics_dict[model][filter] = {}
|
179 |
+
for filter_range in filter_ranges:
|
180 |
+
filter_range_name = filter_range[0]
|
181 |
+
metrics_dict[model][filter][filter_range_name] = {}
|
182 |
+
return metrics_dict
|
183 |
+
|
184 |
+
|
185 |
def calculate_from_payload(payload: dict,
|
186 |
max_iou: float = 0.5,
|
187 |
filters = {},
|
188 |
recognition_thresholds = [0.3, 0.5, 0.8],
|
189 |
debug: bool = False):
|
190 |
+
|
191 |
if not isinstance(payload, dict):
|
192 |
try:
|
193 |
payload = payload.to_dict()
|
|
|
205 |
print("sequence_list: ", sequence_list)
|
206 |
|
207 |
metrics_per_sequence = {}
|
208 |
+
metrics_global = build_metrics_template(models, filters)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
209 |
|
210 |
for sequence in sequence_list:
|
211 |
metrics_per_sequence[sequence] = {}
|
|
|
223 |
index = detection['index']
|
224 |
x, y, w, h = detection['bounding_box']
|
225 |
all_formated_references["all"].append([frame_id+1, index, x, y, w, h])
|
226 |
+
|
227 |
for filter, filter_ranges in filters.items():
|
228 |
filter_value = detection[filter]
|
229 |
for filter_range in filter_ranges:
|
230 |
+
filter_range_name, filter_range_limits = filter_range[0], filter_range[1]
|
|
|
231 |
if filter_value >= filter_range_limits[0] and filter_value <= filter_range_limits[1]:
|
232 |
all_formated_references[filter][filter_range_name].append([frame_id+1, index, x, y, w, h])
|
233 |
|
234 |
+
metrics_per_sequence[sequence] = build_metrics_template(models, filters)
|
235 |
+
|
236 |
for model in models:
|
237 |
frames = payload['sequences'][sequence][model]
|
238 |
formated_predictions = []
|
|
|
241 |
for detection in frame:
|
242 |
index = detection['index']
|
243 |
x, y, w, h = detection['bounding_box']
|
244 |
+
confidence = 1
|
|
|
245 |
formated_predictions.append([frame_id+1, index, x, y, w, h, confidence])
|
246 |
+
|
247 |
if debug:
|
248 |
print("sequence/model: ", sequence, model)
|
249 |
print("formated_predictions: ", formated_predictions)
|
250 |
print("formated_references: ", all_formated_references)
|
251 |
+
|
252 |
if len(formated_predictions) == 0:
|
253 |
metrics_per_sequence[sequence][model] = "Model had no predictions."
|
254 |
elif len(all_formated_references["all"]) == 0:
|
255 |
metrics_per_sequence[sequence][model] = "No ground truth."
|
256 |
+
|
257 |
else:
|
|
|
258 |
|
259 |
sequence_metrics = calculate(formated_predictions, all_formated_references["all"], max_iou=max_iou, recognition_thresholds = recognition_thresholds)
|
260 |
sequence_metrics = realize_metrics(sequence_metrics, recognition_thresholds)
|
|
|
264 |
metrics_global[model]["all"] = realize_metrics(metrics_global[model]["all"], recognition_thresholds)
|
265 |
|
266 |
for filter, filter_ranges in filters.items():
|
267 |
+
|
268 |
for filter_range in filter_ranges:
|
269 |
|
270 |
filter_range_name = filter_range[0]
|
|
|
300 |
|
301 |
def realize_metrics(metrics_dict,
|
302 |
recognition_thresholds):
|
303 |
+
"""
|
304 |
+
calculates metrics based on raw metrics
|
305 |
+
"""
|
306 |
|
307 |
metrics_dict["precision"] = metrics_dict["tp"]/(metrics_dict["tp"]+metrics_dict["fp"])
|
308 |
metrics_dict["recall"] = metrics_dict["tp"]/(metrics_dict["tp"]+metrics_dict["fn"])
|
|
|
313 |
|
314 |
return metrics_dict
|
315 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|