peak_finding
sleap_nn.inference.peak_finding
¶
Backward-compatibility re-export shim for peak finding.
The implementations live in :mod:sleap_nn.inference.ops.peaks and
:mod:sleap_nn.inference.ops.crops after PR 1 of #508. This module
preserves the old import path for existing callers; it is scheduled for
deletion in #519 alongside the rest of the legacy inference layout.
Functions:
| Name | Description |
|---|---|
crop_bboxes |
Crop bounding boxes from a batch of images. |
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). |
crop_bboxes(images, bboxes, sample_inds)
¶
Crop bounding boxes from a batch of images.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
Tensor
|
|
required |
bboxes
|
Tensor
|
|
required |
sample_inds
|
Tensor
|
|
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
|
Notes
Bbox top-lefts are floored to the integer grid before extraction,
matching the prior .to(torch.long) behavior. Out-of-image
sample positions are zero-padded.
See Also
:func:make_centered_bboxes.
Source code in sleap_nn/inference/ops/crops.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
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 |