-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
helpers.py
35 lines (29 loc) · 883 Bytes
/
helpers.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
"""
Helper functions.
"""
def get_object_classes(predictions, confidence):
"""
Get a list of the unique object classes predicted.
"""
classes = [
pred["label"] for pred in predictions if float(pred["confidence"]) >= confidence
]
return set(classes)
def get_object_instances(predictions, target, confidence):
"""
Return the number of instances of a target class.
"""
targets_identified = [
pred
for pred in predictions
if pred["label"] == target and float(pred["confidence"]) >= confidence
]
return len(targets_identified)
def get_objects_summary(predictions, confidence):
"""
Get a summary of the objects detected.
"""
classes = get_object_classes(predictions, confidence)
return {
label: get_object_instances(predictions, label, confidence) for label in classes
}