single_instance
sleap_nn.export.wrappers.single_instance
¶
Single-instance ONNX wrapper.
Classes:
| Name | Description |
|---|---|
SingleInstanceONNXWrapper |
ONNX-exportable wrapper for single-instance models. |
SingleInstanceONNXWrapper
¶
Bases: BaseExportWrapper
ONNX-exportable wrapper for single-instance models.
This wrapper handles full-frame inference assuming a single instance per frame. For each body part (channel), it finds the global maximum in the confidence map.
Expects input images as uint8 tensors in [0, 255].
Attributes:
| Name | Type | Description |
|---|---|---|
model |
The trained backbone model that outputs confidence maps. |
|
output_stride |
Output stride of the model (e.g., 4 means confmaps are ¼ the input resolution). |
|
input_scale |
Factor to scale input images before inference. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the single-instance wrapper. |
forward |
Run single-instance inference. |
Source code in sleap_nn/export/wrappers/single_instance.py
__init__(model, output_stride=4, input_scale=1.0, peak_threshold=0.2)
¶
Initialize the single-instance wrapper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
The trained backbone model. |
required |
output_stride
|
int
|
Output stride of the model. Default: 4. |
4
|
input_scale
|
float
|
Factor to scale input images. Default: 1.0. |
1.0
|
peak_threshold
|
float
|
Minimum confidence for a peak to be considered valid. |
0.2
|
Source code in sleap_nn/export/wrappers/single_instance.py
forward(image)
¶
Run single-instance inference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Tensor
|
Input image tensor of shape (batch, channels, height, width). Expected as uint8 [0, 255] values. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Tensor]
|
Dictionary with: peaks: Peak coordinates of shape (batch, n_nodes, 2) in (x, y) format. peak_vals: Peak confidence values of shape (batch, n_nodes). |