receptivefield
sleap.gui.learning.receptivefield
¶
Widget for previewing receptive field on sample image using model hyperparams.
Classes:
| Name | Description |
|---|---|
ReceptiveFieldImageWidget |
Widget for showing image with receptive field and optional crop box. |
ReceptiveFieldWidget |
Widget for previewing receptive field on sample image, with caption. |
Functions:
| Name | Description |
|---|---|
compute_anchor_point |
Computes the anchor point for an instance. |
compute_crop_size_from_cfg |
Computes crop size from model configuration. |
compute_rf |
Computes receptive field for specified model architecture. |
find_instance_crop_size |
Compute the size of the largest instance bounding box from labels. |
find_max_instance_bbox_size |
Find the maximum bounding box dimension across all instances in labels. |
get_first_labeled_frame_and_instance |
Gets the first frame with ground truth labels and the first instance. |
receptive_field_info_from_model_cfg |
Gets receptive field and architecture information from model configuration. |
ReceptiveFieldImageWidget
¶
Bases: GraphicsView
Widget for showing image with receptive field and optional crop box.
Methods:
| Name | Description |
|---|---|
viewportEvent |
Re-draw receptive field and crop box when needed. |
Source code in sleap/gui/learning/receptivefield.py
763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 | |
viewportEvent(event)
¶
Re-draw receptive field and crop box when needed.
Source code in sleap/gui/learning/receptivefield.py
ReceptiveFieldWidget
¶
Bases: QWidget
Widget for previewing receptive field on sample image, with caption.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
head_name
|
Text
|
If given, then used in caption to show which model the preview is for. |
''
|
show_crop_box
|
bool
|
If True, shows a crop size box centered on anchor point. This is intended for centered_instance and multi_class_topdown heads. |
False
|
Usage
Create, then call setImage and setModelConfig methods.
For crop box display, also call setLabels and setCropConfig.
Methods:
| Name | Description |
|---|---|
addButtonWidget |
Add a widget (typically a button) between the legend and explanation. |
setCropConfig |
Sets crop box configuration. |
setImage |
Sets image on which receptive field box will be drawn. |
setLabels |
Sets labels and displays the first labeled frame. |
setModelConfig |
Updates receptive field preview from model config. |
Source code in sleap/gui/learning/receptivefield.py
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 525 526 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 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 | |
addButtonWidget(widget)
¶
Add a widget (typically a button) between the legend and explanation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
widget
|
QWidget
|
The widget to add (e.g., QPushButton for "Analyze Sizes...") |
required |
Source code in sleap/gui/learning/receptivefield.py
setCropConfig(crop_size, scale, anchor_part=None)
¶
Sets crop box configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
crop_size
|
Optional[int]
|
The crop size in pixels. |
required |
scale
|
float
|
The scale factor applied to the image during training. |
required |
anchor_part
|
Optional[Text]
|
The name of the body part to use as anchor. If None, the mean of all keypoints is used. |
None
|
Source code in sleap/gui/learning/receptivefield.py
setImage(*args, **kwargs)
¶
setLabels(labels, fallback_video=None)
¶
Sets labels and displays the first labeled frame.
This finds the first frame with ground truth labels, displays that frame, and stores the instance for crop box anchor point calculation (if enabled).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
Optional[Labels]
|
The Labels object containing labeled frames. |
required |
fallback_video
|
Video to use for getting test frame if labeled frame cannot be loaded. |
None
|
Source code in sleap/gui/learning/receptivefield.py
setModelConfig(model_cfg, scale)
¶
Updates receptive field preview from model config.
Source code in sleap/gui/learning/receptivefield.py
compute_anchor_point(instance, anchor_part=None)
¶
Computes the anchor point for an instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
Optional[Instance]
|
The instance to compute the anchor point for. |
required |
anchor_part
|
Optional[Text]
|
The name of the body part to use as anchor. If None, the mean of all visible keypoints is used. |
None
|
Returns:
| Type | Description |
|---|---|
Optional[Tuple[float, float]]
|
A tuple (x, y) representing the anchor point coordinates, or None if the anchor cannot be computed. |
Source code in sleap/gui/learning/receptivefield.py
compute_crop_size_from_cfg(data_cfg, model_cfg, labels=None, aug_form_data=None)
¶
Computes crop size from model configuration.
When crop_size is not set (None/auto), computes it from the largest user-labeled instance bounding box plus augmentation padding, matching the logic in sleap-nn's training pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_cfg
|
OmegaConf
|
Data configuration OmegaConf from the data form. |
required |
model_cfg
|
OmegaConf
|
Model configuration OmegaConf from the model form. |
required |
labels
|
Optional[Labels]
|
Labels object for computing instance bounding boxes. |
None
|
aug_form_data
|
Optional[dict]
|
Raw dict from the augmentation form's get_form_data(), used to compute augmentation padding from virtual fields. |
None
|
Source code in sleap/gui/learning/receptivefield.py
compute_rf(down_blocks, convs_per_block=2, kernel_size=3)
¶
Computes receptive field for specified model architecture.
Ref: https://distill.pub/2019/computing-receptive-fields/ (Eq. 2)
Source code in sleap/gui/learning/receptivefield.py
find_instance_crop_size(labels, padding=0, maximum_stride=2, min_crop_size=None)
¶
Compute the size of the largest instance bounding box from labels.
This is a local implementation that avoids importing sleap_nn (which would trigger importing torch, adding ~2s to startup time).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
Labels
|
A |
required |
padding
|
int
|
Integer number of pixels to add to the bounds as margin padding. |
0
|
maximum_stride
|
int
|
Ensure that the returned crop size is divisible by this value. Useful for ensuring that the crop size will not be truncated in a given architecture. |
2
|
min_crop_size
|
Optional[int]
|
The minimum crop size to return. If this value is already divisible by maximum_stride, it is returned directly. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
An integer crop size denoting the length of the side of the bounding
boxes that will contain the instances when cropped. The returned crop
size will be larger or equal to the input |
Source code in sleap/gui/learning/receptivefield.py
find_max_instance_bbox_size(labels)
¶
Find the maximum bounding box dimension across all instances in labels.
This is a local implementation that avoids importing sleap_nn (which would trigger importing torch, adding ~2s to startup time).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
Labels
|
A |
required |
Returns:
| Type | Description |
|---|---|
float
|
The maximum bounding box dimension (max of width or height) across all instances. |
Source code in sleap/gui/learning/receptivefield.py
get_first_labeled_frame_and_instance(labels)
¶
Gets the first frame with ground truth labels and the first instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
Optional[Labels]
|
The Labels object containing labeled frames. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[Optional[ndarray], Optional[Instance]]
|
A tuple of (frame_image, instance) where frame_image is a numpy array and instance is the first user instance. Returns (None, None) if no labeled frames with user instances are found. |
Source code in sleap/gui/learning/receptivefield.py
receptive_field_info_from_model_cfg(cfg)
¶
Gets receptive field and architecture information from model configuration.
Returns a dict with
- size: Receptive field size in pixels
- max_stride: Maximum stride (bottleneck)
- down_blocks: Number of encoder downsampling blocks
- convs_per_block: Convolutions per block (fixed at 2)
- kernel_size: Convolution kernel size (fixed at 3)
- output_stride: Minimum head output stride (for RF calculation)
- params: Total backbone parameter count
- params_formatted: Human-readable param count (e.g., "1.30M")
- head_features: List of (head_name, output_stride, channels) for each head
- backbone_type: Type of backbone (unet, convnext, swint)
- model_type: For convnext/swint, the model variant (tiny, small, base, large)
Source code in sleap/gui/learning/receptivefield.py
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 | |