The idea of NMS is to remove boxes that overlap the box with the highest probability. We therefore remove boxes that are non-maximum. To do so, we sort all the boxes by probability, taking the ones with the highest probability first. Then, for each box, we compute the IoU with all the other boxes.
After computing the IoU between a box and the other boxes, we remove the ones with an IoU above a certain threshold (the threshold is usually around 0.5-0.9).
With pseudo-code, this is what NMS would look like:
sorted_boxes = sort_boxes_by_confidence(boxes)
ids_to_suppress = []
for maximum_box in sorted_boxes:
for idx, box in enumerate(boxes):
iou = compute_iou(maximum_box, box)
if iou > iou_threshold:
ids_to_suppress.append(idx)
processed_boxes = np.delete(boxes, ids_to_suppress)
In practice, TensorFlow provides its own implementation of NMS, tf.image.non_max_suppression(boxes, ...) (refer to the documentation at https://www.tensorflow.org/api_docs/python...