Table of Contents

Class NMS<T>

Namespace
AiDotNet.ComputerVision.Detection.PostProcessing
Assembly
AiDotNet.dll

Implements Non-Maximum Suppression (NMS) algorithms for removing duplicate detections.

public class NMS<T>

Type Parameters

T

The numeric type used for calculations.

Inheritance
NMS<T>
Inherited Members

Remarks

For Beginners: When an object detector runs, it often produces multiple overlapping bounding boxes for the same object. NMS removes these duplicates by: 1. Keeping the detection with highest confidence 2. Removing other detections that overlap too much with it 3. Repeating until all duplicates are removed

Constructors

NMS()

Creates a new NMS instance.

public NMS()

Methods

Apply(List<Detection<T>>, double)

Performs standard NMS on a list of detections.

public List<Detection<T>> Apply(List<Detection<T>> detections, double iouThreshold)

Parameters

detections List<Detection<T>>

List of detections to filter.

iouThreshold double

IoU threshold above which boxes are considered duplicates.

Returns

List<Detection<T>>

Filtered list of detections.

Remarks

For Beginners: This is the classic NMS algorithm: 1. Sort detections by confidence (highest first) 2. Take the top detection, add to results 3. Remove all detections that overlap with it by more than iouThreshold 4. Repeat until no detections remain

ApplyBatched(List<List<Detection<T>>>, double, bool)

Performs batched NMS for efficient processing of multiple images.

public List<List<Detection<T>>> ApplyBatched(List<List<Detection<T>>> batchDetections, double iouThreshold, bool classAware = true)

Parameters

batchDetections List<List<Detection<T>>>

Detections grouped by image index.

iouThreshold double

IoU threshold for suppression.

classAware bool

Whether to apply class-aware NMS.

Returns

List<List<Detection<T>>>

Filtered detections for each image.

ApplyClassAware(List<Detection<T>>, double)

Performs class-aware NMS (applies NMS separately per class).

public List<Detection<T>> ApplyClassAware(List<Detection<T>> detections, double iouThreshold)

Parameters

detections List<Detection<T>>

List of detections to filter.

iouThreshold double

IoU threshold for suppression.

Returns

List<Detection<T>>

Filtered list of detections.

Remarks

For Beginners: Class-aware NMS only suppresses boxes of the same class. This allows a "person" detection to overlap with a "car" detection without either being suppressed.

ComputeCIoU(BoundingBox<T>, BoundingBox<T>)

Computes Complete IoU (CIoU) between two bounding boxes.

public double ComputeCIoU(BoundingBox<T> box1, BoundingBox<T> box2)

Parameters

box1 BoundingBox<T>

First bounding box.

box2 BoundingBox<T>

Second bounding box.

Returns

double

CIoU value.

Remarks

For Beginners: CIoU extends DIoU by also considering aspect ratio. This provides the best localization accuracy and is used in modern YOLO versions.

ComputeDIoU(BoundingBox<T>, BoundingBox<T>)

Computes Distance IoU (DIoU) between two bounding boxes.

public double ComputeDIoU(BoundingBox<T> box1, BoundingBox<T> box2)

Parameters

box1 BoundingBox<T>

First bounding box.

box2 BoundingBox<T>

Second bounding box.

Returns

double

DIoU value.

Remarks

For Beginners: DIoU adds a penalty based on the distance between box centers. This helps with faster convergence during training and better localization.

ComputeGIoU(BoundingBox<T>, BoundingBox<T>)

Computes Generalized IoU (GIoU) between two bounding boxes.

public double ComputeGIoU(BoundingBox<T> box1, BoundingBox<T> box2)

Parameters

box1 BoundingBox<T>

First bounding box.

box2 BoundingBox<T>

Second bounding box.

Returns

double

GIoU value between -1 and 1.

Remarks

For Beginners: GIoU is an improved version of IoU that also considers the smallest enclosing box. Unlike IoU, GIoU can be negative when boxes don't overlap but provides gradients even for non-overlapping boxes.

ComputeIoU(BoundingBox<T>, BoundingBox<T>)

Computes Intersection over Union (IoU) between two bounding boxes.

public double ComputeIoU(BoundingBox<T> box1, BoundingBox<T> box2)

Parameters

box1 BoundingBox<T>

First bounding box.

box2 BoundingBox<T>

Second bounding box.

Returns

double

IoU value between 0 and 1.

Remarks

For Beginners: IoU measures how much two boxes overlap: - IoU = 0: No overlap - IoU = 1: Boxes are identical - IoU = 0.5: About 50% overlap