heads
sleap_nn.architectures.heads
¶
Model head definitions for defining model output types.
Classes:
| Name | Description |
|---|---|
BBoxCenterHead |
Center heatmap head of a |
BBoxOffsetHead |
Sub-cell center offset head of a |
BBoxSizeHead |
Box size (width, height in output-grid cells) head of a |
CenterOffsetHead |
Head for predicting per-pixel offset vectors to instance centers. |
CenteredInstanceConfmapsHead |
Head for specifying centered instance confidence maps. |
CentroidConfmapsHead |
Head for specifying instance centroid confidence maps. |
ClassMapsHead |
Head for specifying class identity maps. |
ClassVectorsHead |
Head for specifying classification heads. |
EmbeddingHead |
Head for crop -> embedding-vector (re-ID) models. |
GeM |
Generalized-mean pooling: |
Head |
Base class for model output heads. |
InstanceCenterHead |
Head for predicting instance center heatmaps. |
L2Norm |
L2-normalize along |
MultiInstanceConfmapsHead |
Head for specifying multi-instance confidence maps. |
MultiScaleHead |
Base class for heads that read several backbone strides at once. |
OffsetRefinementHead |
Head for specifying offset refinement maps. |
PartAffinityFieldsHead |
Head for specifying multi-instance part affinity fields. |
SSDHead |
Multi-scale anchor head of a |
SegmentationHead |
Head for predicting binary foreground segmentation masks. |
SingleInstanceConfmapsHead |
Head for specifying single instance confidence maps. |
Functions:
| Name | Description |
|---|---|
default_embedding_pool |
The pooling an |
embedding_encoder_is_frozen |
Whether an |
BBoxCenterHead
¶
Bases: Head
Center heatmap head of a bbox_centernet (CenterNet-style) detector.
One channel per box category; outputs logits (the sigmoid is applied by the loss and the inference forward) so the bias can take the focal-loss prior initialization.
Attributes:
| Name | Type | Description |
|---|---|---|
categories |
Ordered class names, one channel each. |
|
output_stride |
Stride of the output head tensor. |
|
loss_weight |
Weight of the loss term for this head during optimization. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the object with the specified attributes. |
Source code in sleap_nn/architectures/heads.py
channels
property
¶
Return the number of channels in the tensor output by this head.
loss_function
property
¶
Return the name of the loss function to use for this head.
__init__(categories, output_stride=4, loss_weight=1.0)
¶
Initialize the object with the specified attributes.
Source code in sleap_nn/architectures/heads.py
BBoxOffsetHead
¶
Bases: Head
Sub-cell center offset head of a bbox_centernet.
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the object with the specified attributes. |
Attributes:
| Name | Type | Description |
|---|---|---|
channels |
int
|
Return the number of channels in the tensor output by this head. |
loss_function |
str
|
Return the name of the loss function to use for this head. |
Source code in sleap_nn/architectures/heads.py
BBoxSizeHead
¶
Bases: Head
Box size (width, height in output-grid cells) head of a bbox_centernet.
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the object with the specified attributes. |
Attributes:
| Name | Type | Description |
|---|---|---|
channels |
int
|
Return the number of channels in the tensor output by this head. |
loss_function |
str
|
Return the name of the loss function to use for this head. |
Source code in sleap_nn/architectures/heads.py
CenterOffsetHead
¶
Bases: Head
Head for predicting per-pixel offset vectors to instance centers.
Outputs a 2-channel map where each pixel's value is (dx, dy) pointing from the pixel to its instance's center. Only meaningful on foreground pixels.
Attributes:
| Name | Type | Description |
|---|---|---|
output_stride |
Stride of the output head tensor. |
|
loss_weight |
Weight of the loss term for this head during optimization. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the object with the specified attributes. |
Source code in sleap_nn/architectures/heads.py
CenteredInstanceConfmapsHead
¶
Bases: Head
Head for specifying centered instance confidence maps.
Attributes:
| Name | Type | Description |
|---|---|---|
part_names |
List of strings specifying the part names associated with channels. |
|
anchor_part |
Name of the part to use as an anchor node. If not specified, the bounding box centroid will be used. |
|
centroid_method |
How the centroid is derived from the instance's points --
|
|
centroid_fallback |
Reduce method used when |
|
sigma |
Spread of the confidence maps. |
|
output_stride |
Stride of the output head tensor. The input tensor is expected to be at the same stride. |
|
loss_weight |
Weight of the loss term for this head during optimization. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the object with the specified attributes. |
from_config |
Create this head from a set of configurations. |
Source code in sleap_nn/architectures/heads.py
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 | |
channels
property
¶
Return the number of channels in the tensor output by this head.
__init__(part_names, anchor_part=None, centroid_method=None, centroid_fallback=None, sigma=5.0, output_stride=1, loss_weight=1.0)
¶
Initialize the object with the specified attributes.
Source code in sleap_nn/architectures/heads.py
from_config(config, part_names=None)
classmethod
¶
Create this head from a set of configurations.
Attributes:
| Name | Type | Description |
|---|---|---|
config |
A |
|
part_names |
Text name of the body parts (nodes) that the head will be
configured to produce. The number of parts determines the number of
channels in the output. This must be provided if the |
Returns:
| Type | Description |
|---|---|
CenteredInstanceConfmapsHead
|
The instantiated head with the specified configuration options. |
Source code in sleap_nn/architectures/heads.py
CentroidConfmapsHead
¶
Bases: Head
Head for specifying instance centroid confidence maps.
Attributes:
| Name | Type | Description |
|---|---|---|
anchor_part |
Name of the part to use as an anchor node. If not specified, the bounding box centroid will be used. |
|
centroid_source |
Data-pipeline setting for which centroid the model is
trained to predict ( |
|
centroid_method |
How the centroid is derived from the instance's points --
|
|
centroid_fallback |
Reduce method used when |
|
sigma |
Spread of the confidence maps. |
|
output_stride |
Stride of the output head tensor. The input tensor is expected to be at the same stride. |
|
loss_weight |
Weight of the loss term for this head during optimization. |
|
use_sigmoid_activation |
If |
|
focal_loss_alpha |
Training-loss metadata only (does not affect the head
tensor); kept so the head is constructible from
|
|
focal_loss_beta |
Same as |
|
focal_loss_pos_threshold |
Same as |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the object with the specified attributes. |
from_config |
Create this head from a set of configurations. |
Source code in sleap_nn/architectures/heads.py
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 237 238 | |
activation
property
¶
Return the activation function of the head output layer.
channels
property
¶
Return the number of channels in the tensor output by this head.
__init__(anchor_part=None, centroid_source=None, centroid_method=None, centroid_fallback=None, sigma=5.0, output_stride=1, loss_weight=1.0, use_sigmoid_activation=False, focal_loss_alpha=0.0, focal_loss_beta=4.0, focal_loss_pos_threshold=0.5)
¶
Initialize the object with the specified attributes.
Source code in sleap_nn/architectures/heads.py
from_config(config)
classmethod
¶
Create this head from a set of configurations.
Attributes:
| Name | Type | Description |
|---|---|---|
config |
A |
Returns:
| Type | Description |
|---|---|
CentroidConfmapsHead
|
The instantiated head with the specified configuration options. |
Source code in sleap_nn/architectures/heads.py
ClassMapsHead
¶
Bases: Head
Head for specifying class identity maps.
Attributes:
| Name | Type | Description |
|---|---|---|
classes |
List of string names of the classes. |
|
sigma |
Spread of the class maps around each node. |
|
output_stride |
Stride of the output head tensor. The input tensor is expected to be at the same stride. |
|
loss_weight |
Weight of the loss term for this head during optimization. |
|
class_output |
How the classes map to sleap-io objects ( |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the object with the specified attributes. |
from_config |
Create this head from a set of configurations. |
Source code in sleap_nn/architectures/heads.py
activation
property
¶
Return the activation function of the head output layer.
channels
property
¶
Return the number of channels in the tensor output by this head.
__init__(classes, sigma=5.0, output_stride=1, loss_weight=1.0, class_output='track')
¶
Initialize the object with the specified attributes.
Source code in sleap_nn/architectures/heads.py
from_config(config, classes=None)
classmethod
¶
Create this head from a set of configurations.
Attributes:
| Name | Type | Description |
|---|---|---|
config |
A |
|
classes |
List of string names of the classes that this head will predict.
This must be set if the |
Returns:
| Type | Description |
|---|---|
ClassMapsHead
|
The instantiated head with the specified configuration options. |
Source code in sleap_nn/architectures/heads.py
ClassVectorsHead
¶
Bases: Head
Head for specifying classification heads.
Attributes:
| Name | Type | Description |
|---|---|---|
classes |
List of string names of the classes. |
|
num_fc_layers |
Number of fully connected layers after flattening input features. |
|
num_fc_units |
Number of units (dimensions) in fully connected layers prior to classification output. |
|
output_stride |
Stride of the output head tensor. The input tensor is expected to be at the same stride. |
|
loss_weight |
Weight of the loss term for this head during optimization. |
|
class_output |
How the classes map to sleap-io objects ( |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the object with the specified attributes. |
from_config |
Create this head from a set of configurations. |
make_head |
Make head output tensor from input feature tensor. |
Source code in sleap_nn/architectures/heads.py
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 | |
activation
property
¶
Return the activation function of the head output layer.
channels
property
¶
Return the number of channels in the tensor output by this head.
loss_function
property
¶
Return the name of the loss function to use for this head.
__init__(classes, num_fc_layers=1, num_fc_units=64, global_pool=True, output_stride=1, loss_weight=1.0, class_output='track')
¶
Initialize the object with the specified attributes.
Source code in sleap_nn/architectures/heads.py
from_config(config, classes=None)
classmethod
¶
Create this head from a set of configurations.
Attributes:
| Name | Type | Description |
|---|---|---|
config |
A |
|
classes |
List of string names of the classes that this head will predict.
This must be set if the |
Returns:
| Type | Description |
|---|---|
ClassVectorsHead
|
The instantiated head with the specified configuration options. |
Source code in sleap_nn/architectures/heads.py
make_head(x_in)
¶
Make head output tensor from input feature tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_in
|
int
|
An int for the input shape after applying AdaptiveMaxPool2d on dim=1, assuming inputs of shape (B, C, H, W). |
required |
Returns:
| Type | Description |
|---|---|
Sequential
|
A |
Source code in sleap_nn/architectures/heads.py
EmbeddingHead
¶
Bases: Head
Head for crop -> embedding-vector (re-ID) models.
Mirrors ClassVectorsHead (a pooled, non-spatial head): [pool] -> Flatten ->
num_fc_layers x (Linear+ReLU) -> Linear(embedding_dim) -> [L2Norm]. The pooled
feature comes from the backbone's middle_output (lone head, empty decoder).
Attributes:
| Name | Type | Description |
|---|---|---|
embedding_dim |
Output embedding dimensionality. |
|
num_fc_layers |
Number of FC layers before the embedding output. |
|
num_fc_units |
Units in the pre-embedding FC layers. |
|
pool |
Pooling over the encoder feature map: |
|
normalize |
L2-normalize the output embedding. |
|
output_stride |
Should equal the backbone max_stride (so the decoder is empty
and the head taps |
|
loss_weight |
Weight of the loss term for this head. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the object with the specified attributes. |
from_config |
Create this head from a head-leaf configuration. |
make_head |
Make the head output module from the pooled-feature input channels. |
Source code in sleap_nn/architectures/heads.py
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 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 | |
activation
property
¶
Return the activation function of the head output layer.
channels
property
¶
Return the number of channels in the tensor output by this head.
loss_function
property
¶
Return the loss-function name (informational).
The contrastive loss is batch-level and is driven by the embedding
LightningModule's objective, not by this string.
__init__(embedding_dim=128, num_fc_layers=1, num_fc_units=256, pool='gem', normalize=True, output_stride=1, loss_weight=1.0)
¶
Initialize the object with the specified attributes.
Source code in sleap_nn/architectures/heads.py
from_config(config)
classmethod
¶
Create this head from a head-leaf configuration.
Source code in sleap_nn/architectures/heads.py
make_head(x_in)
¶
Make the head output module from the pooled-feature input channels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_in
|
int
|
Number of channels of the encoder feature map (its channel dim). |
required |
Returns:
| Type | Description |
|---|---|
Sequential
|
An |
Source code in sleap_nn/architectures/heads.py
GeM
¶
Bases: Module
Generalized-mean pooling: (mean(x.clamp(min=eps)^p))^(1/p) over HxW.
The exponent p is learnable (init 3.0). The clamp(min=eps) BEFORE the
fractional power guards against NaNs (a fractional power of a negative/zero base).
Returns a flattened [B, C] tensor.
The forward pass uses p clamped to [GEM_P_MIN, GEM_P_MAX]; the stored
parameter is the raw exponent (same state-dict key and meaning as before the
upper bound existed, so a checkpoint whose p lies in that range produces
exactly the output it did). During training the clamp passes its gradient
straight through (_ClampStraightThrough), so p cannot get stuck at a
bound.
The eps floor also means a NEGATIVE activation contributes as if it were
eps: GeM pools only the positive part of each channel. That is what the
native backbones feed it (their bottleneck ends in a ReLU). A pretrained encoder
ends in a LayerNorm instead (about half its activations are negative); when it
is fine-tuned it adapts and GeM costs nothing, but a FROZEN one cannot, so the
default pool for a frozen pretrained encoder is avg -- see
default_embedding_pool.
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the pooling layer. |
exponent |
The exponent the forward pass uses: |
forward |
Pool |
Source code in sleap_nn/architectures/heads.py
__init__(p=3.0, eps=1e-06, learnable=True)
¶
Initialize the pooling layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
float
|
Initial generalized-mean exponent ( |
3.0
|
eps
|
float
|
Small floor applied to the activation before the power to avoid a fractional power of a non-positive value. |
1e-06
|
learnable
|
bool
|
If |
True
|
Source code in sleap_nn/architectures/heads.py
exponent()
¶
The exponent the forward pass uses: p clamped to the valid range.
Training (train mode, autograd on, learnable p) routes the clamp through
_ClampStraightThrough; everywhere else it is a plain clamp with the same
value, which is also what ONNX export traces.
Source code in sleap_nn/architectures/heads.py
forward(x)
¶
Pool [B, C, H, W] to [B, C] by the generalized mean over HxW.
Source code in sleap_nn/architectures/heads.py
Head
¶
Base class for model output heads.
Attributes:
| Name | Type | Description |
|---|---|---|
output_stride |
Stride of the output head tensor. The input tensor is expected to be at the same stride. |
|
loss_weight |
Weight of the loss term for this head during optimization. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the object with the specified attributes. |
make_head |
Make head output tensor from input feature tensor. |
Source code in sleap_nn/architectures/heads.py
activation
property
¶
Return the activation function of the head output layer.
channels
property
¶
Return the number of channels in the tensor output by this head.
loss_function
property
¶
Return the name of the loss function to use for this head.
name
property
¶
Name of the head.
__init__(output_stride=1, loss_weight=1.0)
¶
Initialize the object with the specified attributes.
make_head(x_in)
¶
Make head output tensor from input feature tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_in
|
int
|
An int input for the input channels. |
required |
Returns:
| Type | Description |
|---|---|
Sequential
|
A |
Source code in sleap_nn/architectures/heads.py
InstanceCenterHead
¶
Bases: Head
Head for predicting instance center heatmaps.
Outputs a single-channel Gaussian heatmap with peaks at each instance's mask centroid. Similar to CentroidConfmapsHead but for mask-derived centers.
Attributes:
| Name | Type | Description |
|---|---|---|
sigma |
Standard deviation of the Gaussian in pixels. |
|
output_stride |
Stride of the output head tensor. |
|
loss_weight |
Weight of the loss term for this head during optimization. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the object with the specified attributes. |
Source code in sleap_nn/architectures/heads.py
L2Norm
¶
Bases: Module
L2-normalize along dim (so embeddings live on the unit hypersphere).
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the layer. |
forward |
L2-normalize |
Source code in sleap_nn/architectures/heads.py
__init__(dim=1)
¶
Initialize the layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dim
|
int
|
Dimension along which to L2-normalize. |
1
|
MultiInstanceConfmapsHead
¶
Bases: Head
Head for specifying multi-instance confidence maps.
Attributes:
| Name | Type | Description |
|---|---|---|
part_names |
List of strings specifying the part names associated with channels. |
|
sigma |
Spread of the confidence maps. |
|
output_stride |
Stride of the output head tensor. The input tensor is expected to be at the same stride. |
|
loss_weight |
Weight of the loss term for this head during optimization. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the object with the specified attributes. |
from_config |
Create this head from a set of configurations. |
Source code in sleap_nn/architectures/heads.py
channels
property
¶
Return the number of channels in the tensor output by this head.
__init__(part_names, sigma=5.0, output_stride=1, loss_weight=1.0)
¶
Initialize the object with the specified attributes.
Source code in sleap_nn/architectures/heads.py
from_config(config, part_names=None)
classmethod
¶
Create this head from a set of configurations.
Attributes:
| Name | Type | Description |
|---|---|---|
config |
A |
|
part_names |
Text name of the body parts (nodes) that the head will be
configured to produce. The number of parts determines the number of
channels in the output. This must be provided if the |
Returns:
| Type | Description |
|---|---|
MultiInstanceConfmapsHead
|
The instantiated head with the specified configuration options. |
Source code in sleap_nn/architectures/heads.py
MultiScaleHead
¶
Bases: Head
Base class for heads that read several backbone strides at once.
Model binds a MultiScaleHead to the feature map at every stride in
output_strides (decoder outputs, plus the bottleneck for the deepest one)
and calls its layer with the list of those maps, finest first.
output_stride is the finest of them.
Attributes:
| Name | Type | Description |
|---|---|---|
output_strides |
Feature strides to read, finest first. |
|
loss_weight |
Weight of the loss term for this head during optimization. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the object with the specified attributes. |
make_head |
Make the head from the input channels of each stride, finest first. |
Source code in sleap_nn/architectures/heads.py
OffsetRefinementHead
¶
Bases: Head
Head for specifying offset refinement maps.
Attributes:
| Name | Type | Description |
|---|---|---|
part_names |
List of strings specifying the part names associated with channels. |
|
sigma_threshold |
Threshold of confidence map values to use for defining the boundary of the offset maps. |
|
output_stride |
Stride of the output head tensor. The input tensor is expected to be at the same stride. |
|
loss_weight |
Weight of the loss term for this head during optimization. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the object with the specified attributes. |
from_config |
Create this head from a set of configurations. |
Source code in sleap_nn/architectures/heads.py
channels
property
¶
Return the number of channels in the tensor output by this head.
__init__(part_names, sigma_threshold=0.2, output_stride=1, loss_weight=1.0)
¶
Initialize the object with the specified attributes.
Source code in sleap_nn/architectures/heads.py
from_config(config, part_names=None, sigma_threshold=0.2, loss_weight=1.0)
classmethod
¶
Create this head from a set of configurations.
Attributes:
| Name | Type | Description |
|---|---|---|
config |
A |
|
part_names |
Text name of the body parts (nodes) that the head will be
configured to produce. The number of parts determines the number of
channels in the output. This must be provided if the |
|
sigma_threshold |
Minimum confidence map value below which offsets will be replaced with zeros. |
|
loss_weight |
Weight of the loss associated with this head. |
Returns:
| Type | Description |
|---|---|
OffsetRefinementHead
|
The instantiated head with the specified configuration options. |
Source code in sleap_nn/architectures/heads.py
PartAffinityFieldsHead
¶
Bases: Head
Head for specifying multi-instance part affinity fields.
Attributes:
| Name | Type | Description |
|---|---|---|
edges |
List of tuples of |
|
sigma |
Spread of the part affinity fields. |
|
output_stride |
Stride of the output head tensor. The input tensor is expected to be at the same stride. |
|
loss_weight |
Weight of the loss term for this head during optimization. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the object with the specified attributes. |
from_config |
Create this head from a set of configurations. |
Source code in sleap_nn/architectures/heads.py
channels
property
¶
Return the number of channels in the tensor output by this head.
__init__(edges, sigma=5.0, output_stride=1, loss_weight=1.0)
¶
Initialize the object with the specified attributes.
Source code in sleap_nn/architectures/heads.py
from_config(config, edges=None)
classmethod
¶
Create this head from a set of configurations.
Attributes:
| Name | Type | Description |
|---|---|---|
config |
A |
|
edges |
List of 2-tuples of the form |
Returns:
| Type | Description |
|---|---|
PartAffinityFieldsHead
|
The instantiated head with the specified configuration options. |
Source code in sleap_nn/architectures/heads.py
SSDHead
¶
Bases: MultiScaleHead
Multi-scale anchor head of a bbox_ssd (SSD-style) detector.
At every pyramid level, a small conv tower feeds two 3x3 predictors: per anchor,
len(categories) + 1 class logits (index 0 is background) and 4 box deltas.
The layer outputs one (B, A_total, len(categories) + 5) tensor with all
levels' anchors concatenated (finest level first).
Attributes:
| Name | Type | Description |
|---|---|---|
categories |
Ordered class names (background excluded). |
|
anchors_per_location |
Anchors at each feature-map cell. |
|
output_strides |
Pyramid level strides, finest first. |
|
head_channels |
Channels of each level's conv tower. |
|
head_convs |
3x3 conv + ReLU layers per tower. |
|
loss_weight |
Weight of the box regression loss. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the object with the specified attributes. |
make_head |
Make the per-level predictor from each level's input channels. |
Source code in sleap_nn/architectures/heads.py
channels
property
¶
Values predicted per anchor (class logits + 4 box deltas).
loss_function
property
¶
Return the name of the loss function to use for this head.
num_logits
property
¶
Class logits per anchor (background included).
__init__(categories, anchors_per_location, output_strides, head_channels=128, head_convs=1, loss_weight=1.0)
¶
Initialize the object with the specified attributes.
Source code in sleap_nn/architectures/heads.py
make_head(x_in)
¶
Make the per-level predictor from each level's input channels.
Source code in sleap_nn/architectures/heads.py
SegmentationHead
¶
Bases: Head
Head for predicting binary foreground segmentation masks.
Outputs a single-channel map with sigmoid activation representing the probability that each pixel belongs to any instance (foreground).
Attributes:
| Name | Type | Description |
|---|---|---|
output_stride |
Stride of the output head tensor. |
|
loss_weight |
Weight of the loss term for this head during optimization. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the object with the specified attributes. |
Source code in sleap_nn/architectures/heads.py
activation
property
¶
Return the activation function of the head output layer.
channels
property
¶
Return the number of channels in the tensor output by this head.
loss_function
property
¶
Return the name of the loss function to use for this head.
__init__(output_stride=2, loss_weight=1.0)
¶
Initialize the object with the specified attributes.
SingleInstanceConfmapsHead
¶
Bases: Head
Head for specifying single instance confidence maps.
Attributes:
| Name | Type | Description |
|---|---|---|
part_names |
List of strings specifying the part names associated with channels. |
|
sigma |
Spread of the confidence maps. |
|
output_stride |
Stride of the output head tensor. The input tensor is expected to be at the same stride. |
|
loss_weight |
Weight of the loss term for this head during optimization. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the object with the specified attributes. |
from_config |
Create this head from a set of configurations. |
Source code in sleap_nn/architectures/heads.py
channels
property
¶
Return the number of channels in the tensor output by this head.
__init__(part_names, sigma=5.0, output_stride=1, loss_weight=1.0)
¶
Initialize the object with the specified attributes.
Source code in sleap_nn/architectures/heads.py
from_config(config, part_names=None)
classmethod
¶
Create this head from a set of configurations.
Attributes:
| Name | Type | Description |
|---|---|---|
config |
A |
|
part_names |
Text name of the body parts (nodes) that the head will be
configured to produce. The number of parts determines the number of
channels in the output. This must be provided if the |
Returns:
| Type | Description |
|---|---|
SingleInstanceConfmapsHead
|
The instantiated head with the specified configuration options. |
Source code in sleap_nn/architectures/heads.py
default_embedding_pool(encoder_frozen)
¶
The pooling an embedding head uses when its config leaves pool unset.
avg for a frozen pretrained encoder, gem for everything else. GeM floors
its input at eps, so it pools only the positive part of each channel; a
pretrained encoder's bottleneck is LayerNorm output (DINOv2-with-registers-base
50% negative, ConvNeXtV2-nano 55%), and a frozen one cannot adapt to that.
Measured on the gerbil re-ID set (8 paired seeds, 3 epochs, val rank-1,
avg - gem): frozen DINOv2-reg-base +0.042 (⅞ seeds, paired t p=0.007), frozen
ConvNeXtV2-nano +0.046 (⅞, p=0.015); fine-tuned ConvNeXtV2-nano -0.001
(p=0.87) and fine-tuned DINOv2-reg-base -0.035 (p=0.31; one avg seed trained
to 0.65 against GeM's 0.91) -- so fine-tuned pretrained encoders keep GeM, as
do the native backbones, whose bottleneck ends in a ReLU.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoder_frozen
|
bool
|
|
required |
Returns:
| Type | Description |
|---|---|
str
|
|
Source code in sleap_nn/architectures/heads.py
embedding_encoder_is_frozen(backbone_type, backbone_config, embedding_config)
¶
Whether an embedding model's pooled feature comes from a frozen pretrained encoder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backbone_type
|
str
|
The backbone type ( |
required |
backbone_config
|
That backbone's config leaf. |
required | |
embedding_config
|
The |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|