Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Obss Sahi Legacy NMS Postprocess

From Leeroopedia


Knowledge Sources
Domains Object_Detection, Postprocessing
Last Updated 2026-02-08 12:00 GMT

Overview

⚠️ DEPRECATED: Legacy pure-Python implementations of Non-Maximum Suppression (NMS) and Union-Merge postprocessing for object detection predictions. Located in sahi/postprocess/legacy/ directory. Superseded by sahi.postprocess.combine.

Description

⚠️ This module is deprecated. It resides in the legacy/ directory and has been superseded by the optimized implementations in sahi.postprocess.combine. See Heuristic:Obss_Sahi_Warning_Deprecated_Legacy_NMS for migration guidance.

The sahi.postprocess.legacy.combine module provides the original Python-based postprocessing classes that preceded the current optimized implementations in sahi.postprocess.combine. It contains three classes:

  • PostprocessPredictions — Base class providing IOU/IOS match calculation, configurable match threshold, and class-agnostic/per-class toggle.
  • NMSPostprocess — Standard greedy NMS: iteratively selects the highest-confidence prediction and removes all overlapping candidates above the match threshold.
  • UnionMergePostprocess — Instead of discarding overlapping predictions, merges their bounding boxes (union), scores (max), and masks (logical OR).

These classes operate on ObjectPrediction instances and use numpy for geometry calculations.

Usage

Use these legacy classes only when backward compatibility with older SAHI versions is required. For new code, prefer the optimized implementations in sahi.postprocess.combine.

Code Reference

Source Location

Signature

class PostprocessPredictions:
    def __init__(
        self,
        match_threshold: float = 0.5,
        match_metric: str = "IOU",
        class_agnostic: bool = True,
    ): ...

class NMSPostprocess(PostprocessPredictions):
    def __call__(
        self,
        object_predictions: list[ObjectPrediction],
    ) -> list[ObjectPrediction]: ...

class UnionMergePostprocess(PostprocessPredictions):
    def __call__(
        self,
        object_predictions: list[ObjectPrediction],
    ) -> list[ObjectPrediction]: ...

Import

from sahi.postprocess.legacy.combine import NMSPostprocess, UnionMergePostprocess

I/O Contract

Inputs

Name Type Required Description
match_threshold float No (default 0.5) IOU/IOS threshold for considering two predictions as overlapping
match_metric str No (default "IOU") Overlap metric: "IOU" (intersection over union) or "IOS" (intersection over smaller)
class_agnostic bool No (default True) If True, match across different category IDs
object_predictions list[ObjectPrediction] Yes Detection predictions to postprocess

Outputs

Name Type Description
selected_object_predictions list[ObjectPrediction] Filtered/merged predictions after NMS or union-merge

Usage Examples

Legacy NMS

from sahi.postprocess.legacy.combine import NMSPostprocess

# Create NMS postprocessor with IOU threshold 0.5
nms = NMSPostprocess(match_threshold=0.5, match_metric="IOU", class_agnostic=True)

# Apply to list of ObjectPrediction instances
filtered_predictions = nms(object_predictions)

Legacy Union Merge

from sahi.postprocess.legacy.combine import UnionMergePostprocess

# Create union-merge postprocessor using IOS metric
merge = UnionMergePostprocess(match_threshold=0.6, match_metric="IOS", class_agnostic=False)

# Apply to list of ObjectPrediction instances
merged_predictions = merge(object_predictions)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment