postprocessing
sleap_nn.inference.postprocessing
¶
Inference-level postprocessing filters for pose predictions.
This module provides filters that run after model inference but before tracking. These filters are independent of tracking configuration and can be used standalone.
Functions:
| Name | Description |
|---|---|
filter_overlapping_instances |
Filter overlapping instances using greedy non-maximum suppression. |
filter_overlapping_instances(labels, threshold=0.8, method='iou')
¶
Filter overlapping instances using greedy non-maximum suppression.
Removes duplicate/overlapping instances by applying greedy NMS based on either bounding box IOU or Object Keypoint Similarity (OKS). When two instances overlap above the threshold, the lower-scoring one is removed.
This filter runs independently of tracking and can be used to clean up model outputs before saving or further processing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
Labels
|
Labels object with predicted instances to filter. |
required |
threshold
|
float
|
Similarity threshold for considering instances as overlapping. Instances with similarity > threshold are candidates for removal. Lower values are more aggressive (remove more). Typical values: 0.3 (aggressive) to 0.8 (permissive). |
0.8
|
method
|
Literal['iou', 'oks']
|
Similarity metric to use for comparing instances. "iou": Bounding box intersection-over-union. "oks": Object Keypoint Similarity (pose-based). |
'iou'
|
Returns:
| Type | Description |
|---|---|
Labels
|
The input Labels object with overlapping instances removed. Modification is done in place, but the object is also returned for convenience. |
Example
Filter instances with >80% bounding box overlap¶
labels = filter_overlapping_instances(labels, threshold=0.8, method="iou")
Filter using OKS similarity¶
labels = filter_overlapping_instances(labels, threshold=0.5, method="oks")
Note
- Only affects frames with 2+ predicted instances
- Uses instance.score for ranking; higher scores are preferred
- For IOU: bounding boxes computed from non-NaN keypoints
- For OKS: uses standard COCO OKS formula with bbox-derived scale