Tensorflow Non-Maximum Suppression
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
TensorFlow's Non-Maximum Suppression (NMS) is a crucial technique used primarily in object detection tasks. It serves to filter out overlapping bounding boxes by selecting only the most probable detections, thus refining the final output regions. This process dramatically increases the efficiency and accuracy of object detection models by eliminating redundant or less likely bounding box predictions.
Understanding Non-Maximum Suppression
The Need for NMS
In object detection models, such as Faster-RCNN, YOLO, or SSD, the network outputs multiple bounding boxes for the objects in an image. These boxes often overlap, leading to multiple detections for the same object. Non-Maximum Suppression helps in selecting the best bounding box from a set of overlapping boxes based on specific scoring criteria.
How NMS Works
- Score-Based Selection: Each bounding box is assigned a score, usually the class prediction probability. NMS starts by sorting all bounding boxes in descending order of their scores.
- IoU Calculation: For each box , the method calculates Intersection over Union (IoU) with every other box. IoU is the ratio of the overlap area to the union area of two bounding boxes.
- Suppress Boxes: If the IoU of a box with is greater than a predefined threshold, is suppressed (removed from consideration).
- Iterate and Repeat: The process repeats recursively, moving through the list sorted by scores, and suppresses boxes with high IoU until all boxes have been checked.
The result is a reduced list of bounding boxes with minimized overlap and high confidence scores for the detected objects.
Implementing NMS in TensorFlow
Basic Usage
TensorFlow provides a dedicated function for Non-Maximum Suppression, tf.image.non_max_suppression. Here is a simple example of implementing NMS:
boxes: A 2-D tensor of shape [num_boxes, 4] representing the coordinates of each box.scores: A 1-D tensor representing the confidence score of each box.max_output_size: The maximum number of boxes to be selected.iou_threshold: A float representing the IoU threshold. Boxes with IoU greater than this value are suppressed.
Related reading
- TensorFlow Non-repeatable results
- Tensorflow None of the MLIR optimization passes are enabled registered 1
- Tensorflow. Nonlinear regression
- TensorFlow Normalization vs Scikit-learn Normalization
- Tensorflow Object-Detection API - How does the Fine-Tuning of a model works?
- Tensorflow Object-Detection API - How does the Fine-Tuning of a model works?
- tensorflow Not creating XLA devices, tf_xla_enable_xla_devices not set
- Tensorflow not detecting GPU - Adding visible gpu devices 0
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.