API reference

GpuNms Class

GPU-accelerated Non-Maximum Suppression utilities.
Uses a compute shader to filter and compact detections so that only a small set of results needs to be read back to the CPU. See ComputeShader and ComputeBuffer for the underlying Unity APIs.

Constructors

GpuNms ( shader )
Signature
GpuNms(ComputeShader shader)
Parameters
shader: ComputeShader

Methods

RunNmsAsync ( boxesBuffer , scoresBuffer , classIdsBuffer , count , iouThreshold , minConfidence , maxKeep , scaleX , scaleY )
Zero-copy GPU gather: runs NMS and writes compact detections directly on the GPU, then reads back only the first maxKeep results.
Use when model outputs are on the GPU (Compute backend).
Signature
Task< List< DetectionDto > > RunNmsAsync(ComputeBuffer boxesBuffer, ComputeBuffer scoresBuffer, ComputeBuffer classIdsBuffer, int count, float iouThreshold, float minConfidence, int maxKeep, float scaleX, float scaleY)
Parameters
boxesBuffer: ComputeBuffer  GPU buffer of float4 boxes (xywh).
scoresBuffer: ComputeBuffer  GPU buffer of scores.
classIdsBuffer: ComputeBuffer  GPU buffer of class IDs.
count: int  Number of candidate boxes.
iouThreshold: float  IoU overlap threshold for suppression.
minConfidence: float  Minimum score to consider a box.
maxKeep: int  Maximum number of kept detections.
scaleX: float  Scale from model input width to source texture width.
scaleY: float  Scale from model input height to source texture height.
Returns
Task< List< DetectionDto > >
RunNmsIndicesAsync ( boxes , scores , classIds , iouThreshold , minConf , maxKeep )
Runs NMS on the GPU and returns kept indices for the provided CPU lists of boxes and scores.
Use when detection results are already on the CPU. See also RunNmsAsync(UnityEngine.ComputeBuffer,UnityEngine.ComputeBuffer,UnityEngine.ComputeBuffer,int,float,float,int,float,float) for the zero-copy GPU gather path.
Signature
Task< List< int > > RunNmsIndicesAsync(List< Vector4 > boxes, List< float > scores, List< int > classIds, float iouThreshold=0.5f, float minConf=0.5f, int maxKeep=100)
Parameters
boxes: List< Vector4 >
scores: List< float >
classIds: List< int >
iouThreshold: float
minConf: float
maxKeep: int
Returns
Task< List< int > >

Inner Struct

DetectionDto Struct

Compact detection produced by the GPU gather path.
Each instance contains the scaled rectangle, confidence, and class id for a single kept box after Non-Maximum Suppression. This payload is intentionally minimal so providers can read back only a few bytes per frame and avoid large CPU downloads of full model tensors.
Coordinates in Box are already scaled from the model’s input size into source texture space (x, y, w, h). Map ID to a human-readable label using your class-labels array (for example, those loaded by UnityInferenceEngineProvider). Scores are unitless confidences in [0,1] and are suitable for thresholding or UI display.

Fields

Box : Vector4
Axis-aligned rectangle in source texture space as (x, y, w, h).
The provider applies scaling from model input dimensions so consumers can directly overlay this on the original frame without additional normalization or aspect-ratio math.
Signature
Vector4 Box
ID : int
Zero-based class index emitted by the model for this detection.
Resolve to a descriptive label using the same labels table that was used at inference time to ensure consistent categories.
Signature
int ID
Score : float
Confidence score in the [0,1] range reflecting the model’s belief that this box contains the predicted class.
Use this to sort, filter, or annotate UI elements with a percentage value.
Signature
float Score