peaks
sleap_nn.inference.ops.peaks
¶
Peak finding ops for confidence maps.
Functions provided:
- :func:
morphological_dilation— pure-PyTorch 3×3 dilation used as the non-maximum suppression kernel below. - :func:
integral_regression— sub-pixel refinement by integrating expected coordinates over a local patch. - :func:
find_global_peaks_rough/ :func:find_global_peaks— single peak per (sample, channel) for centroid / single-instance confmaps. - :func:
find_local_peaks_rough/ :func:find_local_peaks— multi-peak finding for bottom-up confmaps.
PR 1 is a pure relocation — every function below preserves the exact
signature and behavior of its old home in sleap_nn/inference/peak_finding.py.
Functions:
| Name | Description |
|---|---|
find_global_peaks |
Find global peaks with optional refinement. |
find_global_peaks_rough |
Find the global maximum for each sample and channel. |
find_local_peaks |
Find local peaks with optional refinement. |
find_local_peaks_rough |
Find local maxima via non-maximum suppression. |
integral_regression |
Compute regression by integrating over the confidence maps on a grid. |
morphological_dilation |
Compute the per-pixel max over the 8-neighborhood (excluding center). |
find_global_peaks(cms, threshold=0.2, refinement=None, integral_patch_size=5)
¶
Find global peaks with optional refinement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cms
|
Tensor
|
|
required |
threshold
|
float
|
Peaks below this are NaN-padded. |
0.2
|
refinement
|
Optional[str]
|
|
None
|
integral_patch_size
|
int
|
Side length of the refinement patch. |
5
|
Returns:
| Type | Description |
|---|---|
Tuple[Tensor, Tensor]
|
|
Source code in sleap_nn/inference/ops/peaks.py
find_global_peaks_rough(cms, threshold=0.1)
¶
Find the global maximum for each sample and channel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cms
|
Tensor
|
|
required |
threshold
|
float
|
Peaks below this are replaced with NaN. |
0.1
|
Returns:
| Type | Description |
|---|---|
Tuple[Tensor, Tensor]
|
|
Source code in sleap_nn/inference/ops/peaks.py
find_local_peaks(cms, threshold=0.2, refinement=None, integral_patch_size=5)
¶
Find local peaks with optional refinement.
Same return shape as :func:find_local_peaks_rough. refinement
accepts None (no refinement) or "integral".
Source code in sleap_nn/inference/ops/peaks.py
find_local_peaks_rough(cms, threshold=0.2)
¶
Find local maxima via non-maximum suppression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cms
|
Tensor
|
|
required |
threshold
|
float
|
Peaks below this are dropped. |
0.2
|
Returns:
| Type | Description |
|---|---|
Tuple[Tensor, Tensor, Tensor, Tensor]
|
|
Source code in sleap_nn/inference/ops/peaks.py
integral_regression(cms, xv, yv)
¶
Compute regression by integrating over the confidence maps on a grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cms
|
Tensor
|
Confidence maps with shape |
required |
xv
|
Tensor
|
|
required |
yv
|
Tensor
|
|
required |
Returns:
| Type | Description |
|---|---|
Tuple[Tensor, Tensor]
|
|
Source code in sleap_nn/inference/ops/peaks.py
morphological_dilation(image, kernel)
¶
Compute the per-pixel max over the 8-neighborhood (excluding center).
Used by :func:find_local_peaks_rough as the NMS dilation step. The
kernel argument is preserved for API compatibility but is currently
ignored — the 8-neighbor pattern is hardcoded so the function lowers
cleanly to torch.stack + max, which exports to ONNX (PR 5 of #508
rewrote the original Tensor.unfold formulation that the legacy ONNX
exporter rejected).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Tensor
|
Input tensor of shape |
required |
kernel
|
Tensor
|
Legacy 3×3 NMS kernel; unused. Kept so existing callers continue to work without modification. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Same shape as |