single_instance
sleap_nn.inference.layers.single_instance
¶
SingleInstanceLayer — single-pose-per-frame inference.
Single-instance models predict one pose per frame from a confmap-only head. The layer:
- Accepts
np.ndarrayortorch.Tensordirectly (real-time / notebook use cases that don't want to spin up asio.Video). - Runs the backend (PyTorch / ONNX / TensorRT) — same code path; the
ModelBackendprotocol abstracts the runtime. - Decodes confmaps to keypoints via :mod:
sleap_nn.inference.ops.peaks. - Reverses the coord ladder via :mod:
sleap_nn.inference.ops.coordsoOutputs.pred_keypointsis in original-image space.
Classes:
| Name | Description |
|---|---|
SingleInstanceLayer |
Single-pose-per-frame inference layer. |
SingleInstanceLayer
¶
Bases: InferenceLayer
Single-pose-per-frame inference layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
ModelBackend
|
Runtime backend (e.g. |
required |
preprocess_config
|
Optional[PreprocessConfig]
|
Pre-forward transformation knobs. |
None
|
postprocess_config
|
Optional[PostprocessConfig]
|
Peak decoding + intermediate-return knobs. |
None
|
output_stride
|
int
|
Stride between confmap and input pixels (read from the head config at construction). |
required |
max_stride
|
int
|
Backbone-network stride; inputs are padded bottom-right
to a multiple of this in |
1
|
Methods:
| Name | Description |
|---|---|
__init__ |
Compose the layer with default empty configs when omitted. |
postprocess |
Decode confmaps → keypoints, reverse coord ladder, build |
Source code in sleap_nn/inference/layers/single_instance.py
__init__(backend, output_stride, max_stride=1, preprocess_config=None, postprocess_config=None)
¶
Compose the layer with default empty configs when omitted.
Source code in sleap_nn/inference/layers/single_instance.py
postprocess(raw_out, info)
¶
Decode confmaps → keypoints, reverse coord ladder, build Outputs.
This layer always runs the torch decode path: it is only ever built
with a TorchBackend (does_baked_postproc=False). The exported
ONNX/TRT path uses the separate :class:ExportedSingleInstanceLayer
adapter, which returns already-final peaks without the coord ladder —
so this method must NOT special-case a baked backend (doing so would
double-apply the ladder; #584).