Reputation: 15
I have an object detection algorithm set up using TensorFlow, is there a way to remove the outliers in terms of the size of the boxes?
For example, I have 20 objects detected. Let's say 17 of them are around 50x50. But, there are a few bounding boxes that are 1x1 and one box that is 1000x1000. Obviously the 1x1 and 1000x1000 boxes are way too big and should be removed.
Upvotes: 1
Views: 857
Reputation: 1667
One way you can do that is to use the z_score. The z_score will check how many std_devs does this number differs from the mean.
Example:
# coding: utf-8
import cv2
import numpy as np
bboxes = [(100,200), (120,210), (114, 195), (2,190), (104, 300), (111, 3), (110, 208), (114,205)]
def z_score(ys):
mean_y = np.mean(ys)
stdev_y = np.std(ys)
z_scores = np.abs([(y - mean_y) / stdev_y for y in ys])
return z_scores
thresh = 1
outliers = [(t[0]>thresh or t[1]>thresh) for t in z_score(bboxes)]
This will print: [False, False, False, True, True, True, False, False]
Upvotes: 1