coord
sleap_nn.inference.ops.coord
¶
Coordinate-ladder reversers for inference.
The current pipeline scatters stride / input_scale / eff_scale /
crop_offset math across every Lightning forward() and across
Predictor._make_labeled_frames_from_generator(). That spread is the
single biggest source of "silent miscalibration" bugs.
This module is the single source of truth for the reverse direction (model output → original-image coordinates). Every step is an early-returnable identity for its no-op case so we don't pay extra ops when the user hasn't configured a transform.
Apply order from a peak in confmap pixel space back to original-image space::
peaks = undo_stride(peaks, info.output_stride) # 1
peaks = undo_input_scale(peaks, info.input_scale) # 2
peaks = add_crop_offset(peaks, info.crop_offsets) # 3 (top-down only)
peaks = undo_eff_scale(peaks, info.eff_scale) # 4
Functions:
| Name | Description |
|---|---|
add_crop_offset |
Shift crop-local peaks back into full-image coordinates (top-down). |
apply_input_scale |
Bilinear resize an image batch by |
undo_eff_scale |
Reverse the per-sample sizematcher scale. |
undo_input_scale |
Reverse the input-scale resize applied during preprocessing. |
undo_stride |
Scale peak coords from confmap pixel space to input-image pixel space. |
add_crop_offset(peaks, crop_topleft)
¶
Shift crop-local peaks back into full-image coordinates (top-down).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
peaks
|
Tensor
|
|
required |
crop_topleft
|
Tensor
|
|
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Peaks shifted into full-image space. |
Source code in sleap_nn/inference/ops/coord.py
apply_input_scale(image, input_scale)
¶
Bilinear resize an image batch by input_scale (forward direction).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Tensor
|
|
required |
input_scale
|
float
|
Scale factor. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Resized image. Output dtype matches input. |
Source code in sleap_nn/inference/ops/coord.py
undo_eff_scale(coords, eff_scale)
¶
Reverse the per-sample sizematcher scale.
The sizematcher fits each frame to (max_h, max_w) preserving aspect
ratio, producing one scalar scale factor per batch sample (not constant).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coords
|
Tensor
|
Tensor with shape |
required |
eff_scale
|
Tensor
|
|
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Coords with each sample divided by its own |
Source code in sleap_nn/inference/ops/coord.py
undo_input_scale(coords, input_scale)
¶
Reverse the input-scale resize applied during preprocessing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coords
|
Tensor
|
Tensor with trailing xy axis. |
required |
input_scale
|
float
|
Scale factor that was applied before the model
( |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Coords divided by |
Source code in sleap_nn/inference/ops/coord.py
undo_stride(coords, output_stride)
¶
Scale peak coords from confmap pixel space to input-image pixel space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coords
|
Tensor
|
Tensor of any shape ending in 2 (the trailing axis is xy). |
required |
output_stride
|
int
|
Stride between input pixels and confmap pixels (>=1). |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Coords scaled by |