We end up with the coordinates and the size of the predicted bounding boxes, as well as the confidence and the class probabilities. All we have to do now is to multiply the confidence by the class probabilities and threshold them in order to only keep high probabilities:
# Confidence is a float, classes is an array of size NUM_CLASSES
final_scores = box_confidence * classes_scores
OBJECT_THRESHOLD = 0.3
# filter will be an array of booleans, True if the number is above threshold
filter = classes_scores >= OBJECT_THRESHOLD
filtered_scores = class_scores * filter
Here is an example of this operation with a simple sample, with a threshold of 0.3 and a box confidence (for this specific box) of 0.5:
CLASS_LABELS |
dog |
airplane |
bird |
elephant |
classes_scores |
0.7 |
0.8 |
0.001 |
0.1 |
final_scores |
0.35 |
0.4 |
0.0005 |
0.05 |
filtered_scores |
0.35 |
0.4 |
0 |
0 |
Then, if filtered_scores contains non-null values, this means we have...