IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).

Mojo function

non_max_suppression

def non_max_suppression[dtype: DType](boxes: TileTensor[dtype, Engine=boxes.Engine, address_space=boxes.address_space, linear_idx_type=boxes.linear_idx_type], scores: TileTensor[dtype, Engine=scores.Engine, address_space=scores.address_space, linear_idx_type=scores.linear_idx_type], output: TileTensor[.int64, Engine=output.Engine, address_space=output.address_space, linear_idx_type=output.linear_idx_type], max_output_boxes_per_class: Int, iou_threshold: Float32, score_threshold: Float32)

Perform Non-Maximum Suppression (NMS) on bounding boxes.

This is a buffer semantic overload that writes results directly to an output tensor. NMS iteratively selects boxes with highest scores while suppressing nearby boxes with high overlap (IoU).

Parameters:

  • ​dtype (DType): The data type for box coordinates and scores.

Args:

def non_max_suppression[dtype: DType, FuncType: def(Int64, Int64, Int64) -> None & ImplicitlyCopyable](boxes: TileTensor[dtype, Engine=boxes.Engine, address_space=boxes.address_space, linear_idx_type=boxes.linear_idx_type], scores: TileTensor[dtype, Engine=scores.Engine, address_space=scores.address_space, linear_idx_type=scores.linear_idx_type], max_output_boxes_per_class: Int, iou_threshold: Float32, score_threshold: Float32, func: FuncType)

Implements the NonMaxSuppression operator from the ONNX spec https://github.com/onnx/onnx/blob/main/docs/Operators.md#nonmaxsuppression.

Parameters:

  • ​dtype (DType): The data type for box coordinates and scores.
  • ​FuncType (def(Int64, Int64, Int64) -> None & ImplicitlyCopyable): Type of the func callback invoked for each selected box.

Args:

def non_max_suppression[dtype: DType, BoxesLayout: TensorLayout, ScoresLayout: TensorLayout, OutputLayout: TensorLayout, BoxesEngine: TensorEngine = DefaultEngine, ScoresEngine: TensorEngine = DefaultEngine, OutputEngine: TensorEngine = DefaultEngine](boxes: ImmTileTensor[dtype, BoxesLayout, ImmutAnyOrigin, Engine=BoxesEngine], scores: ImmTileTensor[dtype, ScoresLayout, ImmutAnyOrigin, Engine=ScoresEngine], output: TileTensor[.int64, OutputLayout, MutAnyOrigin, Engine=OutputEngine], max_output_boxes_per_class: Int, iou_threshold: Float32, score_threshold: Float32, ctx: DeviceContext)

Runs NMS on target, dispatching to the GPU kernel when possible.

The GPU path covers float32 inputs with num_boxes within the shared-memory candidate budget; anything else falls back to the CPU implementation on host copies of the tensors.

Parameters:

  • ​dtype (DType): The data type for box coordinates and scores.
  • ​BoxesLayout (TensorLayout): Layout type of the boxes tensor.
  • ​ScoresLayout (TensorLayout): Layout type of the scores tensor.
  • ​OutputLayout (TensorLayout): Layout type of the output tensor.
  • ​BoxesEngine (TensorEngine): Engine type of the boxes tensor.
  • ​ScoresEngine (TensorEngine): Engine type of the scores tensor.
  • ​OutputEngine (TensorEngine): Engine type of the output tensor.

Args:

Was this page helpful?