bottomup
sleap_nn.inference.layers.bottomup
¶
BottomUpLayer — single-stage multi-instance inference via PAF grouping.
The bottom-up model emits two heads: a multi-instance confidence map
(MultiInstanceConfmapsHead) and part-affinity fields
(PartAffinityFieldsHead). The layer:
- Runs the model.
- Finds local peaks on the confmaps.
- Scores PAF lines between candidate keypoints.
- Groups peaks into instances via the existing :class:
PAFScorer. - NaN-pads the variable per-frame instance count to
max_instancessoOutputs.pred_keypointsretains its canonical(B, I, N, 2)shape.
Steps 1-3 are GPU-friendly tensor ops; step 4 is a CPU-bound
scipy.linear_sum_assignment + BFS instance assembly. The two phases
are split into :meth:_score_pafs_on_gpu (GPU) and the free function
:func:sleap_nn.inference.streaming.group_scored_batch (CPU). The split
enables a worker pool for the CPU phase; the inline path simply calls
them back-to-back inside :meth:postprocess.
Classes:
| Name | Description |
|---|---|
BottomUpLayer |
Bottom-up multi-instance inference layer. |
BottomUpLayer
¶
Bases: InferenceLayer
Bottom-up multi-instance inference layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
ModelBackend
|
Runtime backend wrapping the bottom-up Lightning module (which emits both confmaps and PAFs). |
required |
paf_scorer
|
PAFScorer
|
Pre-configured :class: |
required |
cms_output_stride
|
int
|
Stride between the confmap output and the scaled-input pixels. |
required |
pafs_output_stride
|
int
|
Stride between the PAF output and the
scaled-input pixels (often equal to |
required |
max_instances
|
Optional[int]
|
Cap on instances per frame. Variable bottom-up output is NaN-padded to this fixed shape. |
None
|
max_stride
|
int
|
Maximum stride the model requires for input divisibility (padding applied bottom-right). |
1
|
max_peaks_per_node
|
Optional[int]
|
Skip PAF scoring entirely if any node has
more peaks than this — prevents combinatorial explosion on
noisy early-training models. |
None
|
preprocess_config / postprocess_config
|
Standard knobs. |
required |
Methods:
| Name | Description |
|---|---|
__init__ |
Compose the layer with the PAF scorer + stride config. |
grouping_params |
Snapshot the layer's grouping configuration as a value type. |
postprocess |
GPU peak/PAF scoring + CPU grouping, both in this process. |
Source code in sleap_nn/inference/layers/bottomup.py
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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
__init__(backend, paf_scorer, cms_output_stride, pafs_output_stride, max_instances=None, max_stride=1, max_peaks_per_node=None, preprocess_config=None, postprocess_config=None)
¶
Compose the layer with the PAF scorer + stride config.
Source code in sleap_nn/inference/layers/bottomup.py
grouping_params()
¶
Snapshot the layer's grouping configuration as a value type.
The result is picklable and can be sent to a worker process.
Source code in sleap_nn/inference/layers/bottomup.py
postprocess(raw_out, info)
¶
GPU peak/PAF scoring + CPU grouping, both in this process.