exported
sleap_nn.inference.layers.exported
¶
Export-adapter layers — thin translators around exported ONNX/TRT models.
The exported wrappers in :mod:sleap_nn.export.wrappers bake every
preprocessing + postprocessing step into the ONNX graph, including
input_scale resize, output_stride rescaling, peak finding,
and (top-down) crop extraction. By the time output keys arrive, peaks
are already in original-image pixel space with the right shapes.
The standard :class:InferenceLayer subclasses in
sleap_nn/inference/layers/ were designed for .ckpt checkpoints,
where the layer's own preprocess does the input-scale resize and
postprocess runs the coord ladder (undo_stride /
undo_input_scale). Reusing them for export-loaded backends would
double-apply both transforms.
This module ships dedicated adapter layers for the export path, one per exported model type. Each one:
- skips
input_scaleresize (the wrapper did it) - feeds raw uint8
(B, C, H, W)tensors to the backend - skips peak finding (already baked)
- skips the coord ladder (already in original-image space)
- translates the wrapper's output dict into a structured :class:
Outputs
The classes intentionally don't inherit from :class:InferenceLayer
— they're shaped like layers (predict(image, **kwargs) -> Outputs)
but the layered preprocess/forward/postprocess pipeline doesn't apply.
Classes:
| Name | Description |
|---|---|
ExportedBottomUpLayer |
Adapter for an ONNX/TRT-exported bottom-up model. |
ExportedBottomUpMultiClassLayer |
Adapter for an ONNX/TRT-exported bottom-up multi-class model. |
ExportedCenteredInstanceLayer |
Adapter for an ONNX/TRT-exported centered-instance model. |
ExportedCentroidLayer |
Adapter for an ONNX/TRT-exported centroid model. |
ExportedSingleInstanceLayer |
Adapter for an ONNX/TRT-exported single-instance model. |
ExportedTopDownLayer |
Adapter for an ONNX/TRT-exported combined top-down model. |
ExportedTopDownMultiClassLayer |
Adapter for an ONNX/TRT-exported combined top-down multi-class model. |
ExportedBottomUpLayer
¶
Adapter for an ONNX/TRT-exported bottom-up model.
The bottom-up wrapper (BottomUpONNXWrapper) bakes peak finding +
PAF line scoring into the graph and returns fixed-shape tensors:
peaks:(B, n_nodes, k, 2)in scaled-input pixel space (after multiplication bycms_output_strideinside the graph).peak_vals:(B, n_nodes, k)peak_mask:(B, n_nodes, k)boolline_scores:(B, n_edges, k*k)candidate_mask:(B, n_edges, k*k)bool
What's still left for the CPU to do: the grouping stage —
matching candidates per edge and assembling peaks into instances.
The adapter translates the fixed-shape wrapper output into the
variable-length per-sample :class:ScoredBatch format that
:func:group_scored_batch expects, then runs the same grouping
function the in-flow BottomUpLayer uses inline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
A :class: |
required | |
node_names
|
List of node names from |
required | |
edge_inds
|
List of |
required | |
max_peaks_per_node
|
|
required | |
input_scale
|
The wrapper's baked-in |
required | |
max_instances
|
Optional cap on instances per frame. |
required | |
min_instance_peaks
|
Drop assembled instances with fewer peaks. |
required | |
min_line_scores
|
Per-edge match threshold (forwarded to
:class: |
required | |
peak_conf_threshold
|
Optional runtime peak-confidence threshold. When
set, PAF candidate connections whose src or dst peak confidence is
|
required |
Methods:
| Name | Description |
|---|---|
predict |
Run the backend, translate to |
Source code in sleap_nn/inference/layers/exported.py
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 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | |
predict(image, **_kwargs)
¶
Run the backend, translate to ScoredBatch, run CPU grouping.
Source code in sleap_nn/inference/layers/exported.py
ExportedBottomUpMultiClassLayer
¶
Adapter for an ONNX/TRT-exported bottom-up multi-class model.
Multi-class bottom-up replaces PAF-based grouping with class-map grouping: every detected peak gets a class probability vector, and Hungarian matching assigns peaks to classes per (sample, node).
Wrapper schema:
peaks:(B, n_nodes, k, 2)in scaled-input pixel space.peak_vals:(B, n_nodes, k)peak_mask:(B, n_nodes, k)bool — invalid slots zeroed.class_probs:(B, n_nodes, k, n_classes)— sampled at peaks.
The adapter flattens valid peaks per sample, runs
:func:group_class_peaks (the same Hungarian-matching primitive
the in-flow BottomUpMultiClassLayer uses), and scatters the
grouped peaks into a fixed (B, n_classes, n_nodes, 2).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
A :class: |
required | |
n_nodes
|
Number of skeleton nodes. |
required | |
n_classes
|
Number of identity classes (= |
required | |
input_scale
|
Wrapper's baked-in |
required | |
peak_conf_threshold
|
Optional runtime peak-confidence threshold.
When set, peaks whose confidence is 582).
|
required |
Methods:
| Name | Description |
|---|---|
predict |
Run the backend, flatten + group peaks by class, build |
Source code in sleap_nn/inference/layers/exported.py
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 | |
predict(image, **_kwargs)
¶
Run the backend, flatten + group peaks by class, build Outputs.
Source code in sleap_nn/inference/layers/exported.py
ExportedCenteredInstanceLayer
¶
Adapter for an ONNX/TRT-exported centered-instance model.
Standalone centered-instance is invoked on pre-cropped images. The wrapper outputs the same shape as single-instance:
peaks:(B_crops, N, 2)in crop (x, y) spacepeak_vals:(B_crops, N)
Outputs.pred_keypoints of shape (B_crops, 1, N, 2).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
A :class: |
required | |
return_confmaps
|
Echo |
required |
Methods:
| Name | Description |
|---|---|
predict |
Run the backend and translate to :class: |
Source code in sleap_nn/inference/layers/exported.py
predict(image, **_kwargs)
¶
Run the backend and translate to :class:Outputs.
Source code in sleap_nn/inference/layers/exported.py
ExportedCentroidLayer
¶
Adapter for an ONNX/TRT-exported centroid model.
The wrapper output schema:
centroids:(B, I, 2)in original-image (x, y) space. Invalid slots are zero-filled and flagged ininstance_valid.centroid_vals:(B, I)instance_valid:(B, I)bool
Translates to Outputs.pred_centroids / pred_centroid_values.
Invalid slots are turned into NaN per the Outputs convention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
A :class: |
required | |
anchor_ind
|
Skeleton node index the centroid represents (resolved
from |
required | |
centroid_method
|
The method the exported model was trained to predict
( |
required |
Methods:
| Name | Description |
|---|---|
predict |
Run the backend and translate to :class: |
Source code in sleap_nn/inference/layers/exported.py
predict(image, **_kwargs)
¶
Run the backend and translate to :class:Outputs.
Source code in sleap_nn/inference/layers/exported.py
ExportedSingleInstanceLayer
¶
Adapter for an ONNX/TRT-exported single-instance model.
The wrapper output schema is:
peaks:(B, N, 2)in original-image (x, y) spacepeak_vals:(B, N)confmaps(optional):(B, N, H, W)
Outputs.pred_keypoints uses (B, I, N, 2) so the adapter
inserts a singleton instance dim.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
A :class: |
required | |
return_confmaps
|
When |
required |
Methods:
| Name | Description |
|---|---|
predict |
Run the backend and translate to :class: |
Source code in sleap_nn/inference/layers/exported.py
predict(image, **_kwargs)
¶
Run the backend and translate to :class:Outputs.
Source code in sleap_nn/inference/layers/exported.py
ExportedTopDownLayer
¶
Adapter for an ONNX/TRT-exported combined top-down model.
The export bakes both centroid + centered-instance stages plus the crop extraction step into a single ONNX graph. Wrapper output:
centroids:(B, I, 2)in original-image (x, y) spacecentroid_vals:(B, I)peaks:(B, I, N, 2)in original-image (x, y) space (crop offset already added back inside the graph)peak_vals:(B, I, N)instance_valid:(B, I)bool
Invalid slots are zero-filled by the wrapper and flagged in
instance_valid. The adapter NaN-pads invalid slots per the
Outputs convention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
A :class: |
required |
Methods:
| Name | Description |
|---|---|
predict |
Run the backend and translate to :class: |
Source code in sleap_nn/inference/layers/exported.py
predict(image, **_kwargs)
¶
Run the backend and translate to :class:Outputs.
Source code in sleap_nn/inference/layers/exported.py
ExportedTopDownMultiClassLayer
¶
Adapter for an ONNX/TRT-exported combined top-down multi-class model.
Like :class:ExportedTopDownLayer plus a per-instance class-logits
output. Wrapper schema:
centroids:(B, I, 2)in original-image space.centroid_vals:(B, I)peaks:(B, I, N, 2)in original-image space.peak_vals:(B, I, N)class_logits:(B, I, n_classes)— raw logits.instance_valid:(B, I)bool.
The legacy driver applies softmax to class_logits and runs
Hungarian matching to assign each valid instance to a unique class.
The adapter mirrors that and reorders instances so each output
slot (b, c, ...) holds the instance assigned to class c.
Slots without a matching instance are NaN-padded.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
A :class: |
required | |
n_classes
|
Number of identity classes (= |
required |
Methods:
| Name | Description |
|---|---|
predict |
Run the backend, run softmax + Hungarian, build :class: |
Source code in sleap_nn/inference/layers/exported.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 | |
predict(image, **_kwargs)
¶
Run the backend, run softmax + Hungarian, build :class:Outputs.