Spaces:
Sleeping
Sleeping
add filters
Browse files- user-friendly-metrics.py +33 -9
user-friendly-metrics.py
CHANGED
@@ -89,11 +89,12 @@ class UserFriendlyMetrics(evaluate.Metric):
|
|
89 |
def _compute(self,
|
90 |
payload,
|
91 |
max_iou: float = 0.5,
|
|
|
92 |
recognition_thresholds = [0.3, 0.5, 0.8],
|
93 |
debug: bool = False):
|
94 |
"""Returns the scores"""
|
95 |
# TODO: Compute the different scores of the module
|
96 |
-
return calculate_from_payload(payload, max_iou, recognition_thresholds, debug)
|
97 |
#return calculate(predictions, references, max_iou)
|
98 |
|
99 |
def recognition(track_ratios, th = 0.5):
|
@@ -161,6 +162,7 @@ def calculate(predictions,
|
|
161 |
|
162 |
def calculate_from_payload(payload: dict,
|
163 |
max_iou: float = 0.5,
|
|
|
164 |
recognition_thresholds = [0.3, 0.5, 0.8],
|
165 |
debug: bool = False):
|
166 |
if not isinstance(payload, dict):
|
@@ -184,12 +186,27 @@ def calculate_from_payload(payload: dict,
|
|
184 |
for sequence in sequence_list:
|
185 |
output[sequence] = {}
|
186 |
frames = payload['sequences'][sequence][gt_field_name]
|
187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
for frame_id, frame in enumerate(frames):
|
189 |
for detection in frame:
|
190 |
-
|
191 |
x, y, w, h = detection['bounding_box']
|
192 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
|
194 |
for model in models:
|
195 |
frames = payload['sequences'][sequence][model]
|
@@ -197,21 +214,28 @@ def calculate_from_payload(payload: dict,
|
|
197 |
|
198 |
for frame_id, frame in enumerate(frames):
|
199 |
for detection in frame:
|
200 |
-
|
201 |
x, y, w, h = detection['bounding_box']
|
202 |
confidence = detection['confidence']
|
203 |
confidence = 1 #TODO: remove this line
|
204 |
-
formated_predictions.append([frame_id+1,
|
205 |
if debug:
|
206 |
print("sequence/model: ", sequence, model)
|
207 |
print("formated_predictions: ", formated_predictions)
|
208 |
-
print("formated_references: ",
|
209 |
if len(formated_predictions) == 0:
|
210 |
output[sequence][model] = "Model had no predictions."
|
211 |
-
elif len(
|
212 |
output[sequence][model] = "No ground truth."
|
213 |
else:
|
214 |
-
output[sequence][model] =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
return output
|
216 |
|
217 |
|
|
|
89 |
def _compute(self,
|
90 |
payload,
|
91 |
max_iou: float = 0.5,
|
92 |
+
filters = {},
|
93 |
recognition_thresholds = [0.3, 0.5, 0.8],
|
94 |
debug: bool = False):
|
95 |
"""Returns the scores"""
|
96 |
# TODO: Compute the different scores of the module
|
97 |
+
return calculate_from_payload(payload, max_iou, filters, recognition_thresholds, debug)
|
98 |
#return calculate(predictions, references, max_iou)
|
99 |
|
100 |
def recognition(track_ratios, th = 0.5):
|
|
|
162 |
|
163 |
def calculate_from_payload(payload: dict,
|
164 |
max_iou: float = 0.5,
|
165 |
+
filters = {},
|
166 |
recognition_thresholds = [0.3, 0.5, 0.8],
|
167 |
debug: bool = False):
|
168 |
if not isinstance(payload, dict):
|
|
|
186 |
for sequence in sequence_list:
|
187 |
output[sequence] = {}
|
188 |
frames = payload['sequences'][sequence][gt_field_name]
|
189 |
+
|
190 |
+
all_formated_references = {"all": []}
|
191 |
+
for filter, filter_ranges in filters:
|
192 |
+
all_formated_references[filter] = {}
|
193 |
+
for filter_range in filter_ranges:
|
194 |
+
filter_range_name = filter_range[0]
|
195 |
+
all_formated_references[filter][filter_range_name] = []
|
196 |
+
|
197 |
for frame_id, frame in enumerate(frames):
|
198 |
for detection in frame:
|
199 |
+
index = detection['index']
|
200 |
x, y, w, h = detection['bounding_box']
|
201 |
+
all_formated_references["all"].append([frame_id+1, index, x, y, w, h])
|
202 |
+
for filter, filter_ranges in filters:
|
203 |
+
filter_value = detection[filter]
|
204 |
+
for filter_range in filter_ranges:
|
205 |
+
filter_range_name = filter_range[0]
|
206 |
+
filter_range_limits = filter_range[1]
|
207 |
+
if filter_value >= filter_range_limits[0] and filter_value <= filter_range_limits[1]:
|
208 |
+
all_formated_references[filter][filter_range_name].append([frame_id+1, index, x, y, w, h])
|
209 |
+
|
210 |
|
211 |
for model in models:
|
212 |
frames = payload['sequences'][sequence][model]
|
|
|
214 |
|
215 |
for frame_id, frame in enumerate(frames):
|
216 |
for detection in frame:
|
217 |
+
index = detection['index']
|
218 |
x, y, w, h = detection['bounding_box']
|
219 |
confidence = detection['confidence']
|
220 |
confidence = 1 #TODO: remove this line
|
221 |
+
formated_predictions.append([frame_id+1, index, x, y, w, h, confidence])
|
222 |
if debug:
|
223 |
print("sequence/model: ", sequence, model)
|
224 |
print("formated_predictions: ", formated_predictions)
|
225 |
+
print("formated_references: ", all_formated_references)
|
226 |
if len(formated_predictions) == 0:
|
227 |
output[sequence][model] = "Model had no predictions."
|
228 |
+
elif len(all_formated_references["all"]) == 0:
|
229 |
output[sequence][model] = "No ground truth."
|
230 |
else:
|
231 |
+
output[sequence][model] = {}
|
232 |
+
output[sequence][model]["all"] = calculate(formated_predictions, all_formated_references["all"], max_iou=max_iou, recognition_thresholds = recognition_thresholds)
|
233 |
+
for filter, filter_ranges in filters:
|
234 |
+
output[sequence][model][filter] = {}
|
235 |
+
for filter_range in filter_ranges:
|
236 |
+
filter_range_name = filter_range[0]
|
237 |
+
output[sequence][model][filter][filter_range_name] = calculate(formated_predictions, all_formated_references[filter][filter_range_name], max_iou=max_iou, recognition_thresholds = recognition_thresholds)
|
238 |
+
|
239 |
return output
|
240 |
|
241 |
|