robokudo.utils.non_maxima_suppression

Non-Maxima-Suppression (NMS) implementation for object detection.

This module provides NMS implementations for filtering overlapping bounding boxes.

module:

non_maxima_suppression

synopsis:

Non-Maxima-Suppression for object detection

moduleauthor:

Lennart Heinbokel

Dependencies:

None

Created:

2023-02-02

Functions

_iou(→ float)

Calculate the intersection over union (IoU) of two bounding boxes.

non_max_suppression_(...)

Perform non-maxima suppression (NMS) on object detection results.

class_based_nms(...)

Perform class-based non-maximum suppression (NMS) on object detection results.

Module Contents

robokudo.utils.non_maxima_suppression._iou(box1: typing_extensions.Tuple[int, int, int, int], box2: typing_extensions.Tuple[int, int, int, int]) float

Calculate the intersection over union (IoU) of two bounding boxes.

Parameters:
  • box1 – First bounding box coordinates (x1, y1, x2, y2) where: * x1, y1: coordinates of the top-left corner * x2, y2: coordinates of the bottom-right corner

  • box2 – Second bounding box coordinates in the same format as box1

Returns:

The intersection over union value [0,1]

Example:

box1 = (10, 10, 20, 20)
box2 = (15, 15, 25, 25)
iou = _iou(box1, box2)  # Returns overlap ratio
robokudo.utils.non_maxima_suppression.non_max_suppression_(predictions: typing_extensions.List[typing_extensions.Tuple[typing_extensions.Tuple[int, int, int, int], float, str]], confidence_treshold: float = 0.5, iou_threshold: float = 0.4) typing_extensions.List[typing_extensions.Tuple[typing_extensions.Tuple[int, int, int, int], float, str]]

Perform non-maxima suppression (NMS) on object detection results.

Parameters:
  • predictions – List of tuples, where each tuple contains: * bounding box coordinates (x1, y1, x2, y2) * confidence score * class label

  • confidence_treshold – Minimum confidence score for a box to be considered

  • iou_threshold – IoU threshold above which boxes are considered to overlap

Returns:

Filtered list of predictions after applying NMS

Example:

predictions = [
    ((10, 10, 20, 20), 0.9, "person"),
    ((15, 15, 25, 25), 0.8, "person")
]
filtered = non_max_suppression_(predictions)
robokudo.utils.non_maxima_suppression.class_based_nms(predictions: typing_extensions.List[typing_extensions.Tuple[typing_extensions.Tuple[int, int, int, int], float, str]], confidence_threshold: float = 0.5, iou_threshold: float = 0.4) typing_extensions.List[typing_extensions.Tuple[typing_extensions.Tuple[int, int, int, int], float, str]]

Perform class-based non-maximum suppression (NMS) on object detection results.

Parameters:
  • predictions – List of tuples, where each tuple contains: * bounding box coordinates (x1, y1, x2, y2) * confidence score * class label

  • confidence_threshold – Minimum confidence score for a box to be considered

  • iou_threshold – IoU threshold above which boxes are considered to overlap

Returns:

Filtered list of predictions after applying class-based NMS

Example:

predictions = [
    ((10, 10, 20, 20), 0.9, "person"),
    ((15, 15, 25, 25), 0.8, "car")
]
filtered = class_based_nms(predictions)

Note

This function performs NMS independently for each class, which prevents boxes of different classes from suppressing each other.