model_config
sleap_nn.config.model_config
¶
Serializable configuration classes for specifying all model config parameters.
These configuration classes are intended to specify all the parameters required to initialize the model config.
Classes:
| Name | Description |
|---|---|
BackboneConfig |
Configurations related to model backbone configuration. |
BottomUpConfMapsConfig |
Bottomup configuration map. |
BottomUpConfig |
bottomup head_config. |
BottomUpMultiClassConfig |
Head config for BottomUp Id models. |
BottomUpSegmentationConfig |
Head config for bottom-up instance segmentation models. |
CenterOffsetConfig |
Configuration for the center offset head. |
CenteredInstanceConfMapsConfig |
Centered Instance configuration map. |
CenteredInstanceConfig |
centered_instance head_config. |
CenteredInstanceSegmentationConfig |
Head config for top-down crop-centered instance segmentation models. |
CenteredInstanceSegmentationHeadConfig |
Foreground-mask head config for top-down crop-centered segmentation. |
CentroidConfMapsConfig |
Centroid configuration map. |
CentroidConfig |
centroid head_config. |
ClassMapConfig |
Class map head config. |
ClassVectorsConfig |
Configurations for class vectors heads. |
ConvNextBaseConfig |
Convnext configuration for backbone. |
ConvNextConfig |
Convnext configuration for backbone. |
ConvNextLargeConfig |
Convnext configuration for backbone. |
ConvNextSmallConfig |
Convnext configuration for backbone. |
HeadConfig |
Configurations related to the model output head type. |
InstanceCenterConfig |
Configuration for the instance center heatmap head. |
ModelConfig |
Configurations related to model architecture. |
PAFConfig |
PAF configuration map. |
PretrainedConfig |
Configuration for an external pretrained backbone (HuggingFace). |
SegmentationHeadConfig |
Configuration for the foreground segmentation head. |
SemanticSegmentationConfig |
Head config for whole-frame semantic (foreground) segmentation models. |
SingleInstanceConfMapsConfig |
Single Instance configuration map. |
SingleInstanceConfig |
single instance head_config. |
SwinTBaseConfig |
SwinT configuration for backbone. |
SwinTConfig |
SwinT configuration (tiny) for backbone. |
SwinTSmallConfig |
SwinT configuration (small) for backbone. |
TopDownCenteredInstanceMultiClassConfig |
Head config for TopDown centered instance ID models. |
UNetConfig |
UNet config for backbone. |
UNetLargeRFConfig |
UNet config for backbone with large receptive field. |
UNetMediumRFConfig |
UNet config for backbone with medium receptive field. |
Functions:
| Name | Description |
|---|---|
model_mapper |
Map the legacy model configuration to the new model configuration. |
BackboneConfig
¶
Configurations related to model backbone configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
unet |
Optional[UNetConfig]
|
An instance of |
convnext |
Optional[ConvNextConfig]
|
An instance of |
swint |
Optional[SwinTConfig]
|
An instance of |
pretrained |
Optional[PretrainedConfig]
|
An instance of |
Source code in sleap_nn/config/model_config.py
BottomUpConfMapsConfig
¶
Bottomup configuration map.
Attributes:
| Name | Type | Description |
|---|---|---|
part_names |
Optional[List[str]]
|
(List[str]) None if nodes from sio.Labels file can be used directly. Else provide 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. If not specified, all body parts in the skeleton will be used. This config does not apply for 'PartAffinityFieldsHead'. |
sigma |
float
|
(float) Spread of the Gaussian distribution of the confidence maps as a scalar float. Smaller values are more precise but may be difficult to learn as they have a lower density within the image space. Larger values are easier to learn but are less precise with respect to the peak coordinate. This spread is in units of pixels of the model input image, i.e., the image resolution after any input scaling is applied. |
output_stride |
int
|
(int) The stride of the output confidence maps relative to the input image. This is the reciprocal of the resolution, e.g., an output stride of 2 results in confidence maps that are 0.5x the size of the input. Increasing this value can considerably speed up model performance and decrease memory requirements, at the cost of decreased spatial resolution. |
loss_weight |
Optional[float]
|
(float) Scalar float used to weigh the loss term for this head during training. Increase this to encourage the optimization to focus on improving this specific output in multi-head models. |
Source code in sleap_nn/config/model_config.py
BottomUpConfig
¶
BottomUpMultiClassConfig
¶
BottomUpSegmentationConfig
¶
Head config for bottom-up instance segmentation models.
Source code in sleap_nn/config/model_config.py
CenterOffsetConfig
¶
Configuration for the center offset head.
Attributes:
| Name | Type | Description |
|---|---|---|
output_stride |
int
|
(int) The stride of the output offset maps relative to the input image. Default: 2. |
loss_weight |
float
|
(float) Scalar float used to weigh the loss term for this head during training. Default: 0.1. |
Source code in sleap_nn/config/model_config.py
CenteredInstanceConfMapsConfig
¶
Centered Instance configuration map.
Attributes:
| Name | Type | Description |
|---|---|---|
part_names |
Optional[List[str]]
|
(List[str]) None if nodes from sio.Labels file can be used directly. Else provide 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. If not specified, all body parts in the skeleton will be used. This config does not apply for 'PartAffinityFieldsHead'. |
anchor_part |
Optional[str]
|
(str) Node name to use as the anchor point. If None, the NaN-ignoring mean of all visible instance nodes will be used as the anchor. The same mean-of-visible-nodes fallback is used when the anchor part is specified but not visible in the instance. Setting a reliable anchor point can significantly improve topdown model accuracy as they benefit from a consistent geometry of the body parts relative to the center of the image. Default is None. |
sigma |
float
|
(float) Spread of the Gaussian distribution of the confidence maps as a scalar float. Smaller values are more precise but may be difficult to learn as they have a lower density within the image space. Larger values are easier to learn but are less precise with respect to the peak coordinate. This spread is in units of pixels of the model input image, i.e., the image resolution after any input scaling is applied. |
output_stride |
int
|
(int) The stride of the output confidence maps relative to the input image. This is the reciprocal of the resolution, e.g., an output stride of 2 results in confidence maps that are 0.5x the size of the input. Increasing this value can considerably speed up model performance and decrease memory requirements, at the cost of decreased spatial resolution. |
loss_weight |
float
|
(float) Scalar float used to weigh the loss term for this head during training. Increase this to encourage the optimization to focus on improving this specific output in multi-head models. |
Source code in sleap_nn/config/model_config.py
CenteredInstanceConfig
¶
CenteredInstanceSegmentationConfig
¶
Head config for top-down crop-centered instance segmentation models.
A single foreground-mask head predicting the centered instance's mask on a
centroid crop (the segmentation analog of centered_instance; composed
with a centroid model for full top-down inference).
Source code in sleap_nn/config/model_config.py
CenteredInstanceSegmentationHeadConfig
¶
Foreground-mask head config for top-down crop-centered segmentation.
The bottom-up SegmentationHeadConfig fields plus anchor_part. Keeping
anchor_part INSIDE the head leaf (rather than as a sibling of
segmentation) matches centered_instance's confmaps.anchor_part and
the codebase invariant that every per-type head config is a dict of head-leaf
configs each carrying output_stride — so model/config code that iterates
head leaves (loss weights, output strides, etc.) never trips over it.
Attributes:
| Name | Type | Description |
|---|---|---|
output_stride |
int
|
(int) Stride of the output mask relative to the input crop. Default: 2. |
loss_weight |
float
|
(float) Scalar weight for the bce-dice loss term. Default: 1.0. |
anchor_part |
Optional[str]
|
(str) Optional node name used to center crops during
training. |
Source code in sleap_nn/config/model_config.py
CentroidConfMapsConfig
¶
Centroid configuration map.
Attributes:
| Name | Type | Description |
|---|---|---|
anchor_part |
Optional[str]
|
(str) Node name to use as the anchor point. If None, the NaN-ignoring mean of all visible instance nodes will be used as the anchor. The same mean-of-visible-nodes fallback is used when the anchor part is specified but not visible in the instance. Setting a reliable anchor point can significantly improve topdown model accuracy as they benefit from a consistent geometry of the body parts relative to the center of the image. Default is None. |
centroid_source |
Optional[str]
|
(str) Which centroid the model is trained to predict.
The centroid head must use ONE source for the whole dataset —
mixing user-annotated and computed centroids trains the head against
two conflicting definitions of "centroid". Options:
- |
sigma |
float
|
(float) Spread of the Gaussian distribution of the confidence maps as a scalar float. Smaller values are more precise but may be difficult to learn as they have a lower density within the image space. Larger values are easier to learn but are less precise with respect to the peak coordinate. This spread is in units of pixels of the model input image, i.e., the image resolution after any input scaling is applied. |
output_stride |
int
|
(int) The stride of the output confidence maps relative to the input image. This is the reciprocal of the resolution, e.g., an output stride of 2 results in confidence maps that are 0.5x the size of the input. Increasing this value can considerably speed up model performance and decrease memory requirements, at the cost of decreased spatial resolution. |
Source code in sleap_nn/config/model_config.py
CentroidConfig
¶
ClassMapConfig
¶
Class map head config.
Attributes:
| Name | Type | Description |
|---|---|---|
classes |
Optional[List[str]]
|
(List[str]) List of class (track) names. Default is |
sigma |
float
|
(float) Spread of the Gaussian distribution of the confidence maps as a scalar float. Smaller values are more precise but may be difficult to learn as they have a lower density within the image space. Larger values are easier to learn but are less precise with respect to the peak coordinate. This spread is in units of pixels of the model input image, i.e., the image resolution after any input scaling is applied. |
output_stride |
int
|
(int) The stride of the output confidence maps relative to the input image. This is the reciprocal of the resolution, e.g., an output stride of 2 results in confidence maps that are 0.5x the size of the input. Increasing this value can considerably speed up model performance and decrease memory requirements, at the cost of decreased spatial resolution. |
loss_weight |
Optional[float]
|
(float) Scalar float used to weigh the loss term for this head during training. Increase this to encourage the optimization to focus on improving this specific output in multi-head models. |
Source code in sleap_nn/config/model_config.py
ClassVectorsConfig
¶
Configurations for class vectors heads.
These heads are used in top-down multi-instance models that classify detected points using a fixed set of learned classes (e.g., animal identities).
Attributes:
| Name | Type | Description |
|---|---|---|
classes |
Optional[List[str]]
|
List of string names of the classes that this head will predict. |
num_fc_layers |
int
|
Number of fully-connected layers before the classification output layer. These can help in transforming general image features into classification-specific features. |
num_fc_units |
int
|
Number of units (dimensions) in the fully-connected layers before classification. Increasing this can improve the representational capacity in the pre-classification layers. |
output_stride |
int
|
(Ideally this should be same as the backbone's maxstride). The stride of the output class maps relative to the input image. This is the reciprocal of the resolution, e.g., an output stride of 2 results in maps that are 0.5x the size of the input. This should be the same size as the confidence maps they are associated with. |
loss_weight |
float
|
Scalar float used to weigh the loss term for this head during training. Increase this to encourage the optimization to focus on improving this specific output in multi-head models. |
Source code in sleap_nn/config/model_config.py
ConvNextBaseConfig
¶
Bases: ConvNextConfig
Convnext configuration for backbone.
Attributes:
| Name | Type | Description |
|---|---|---|
pre_trained_weights |
Optional[str]
|
(str) Pretrained weights file name supported only for ConvNext backbones. For ConvNext, one of ["ConvNeXt_Base_Weights", "ConvNeXt_Tiny_Weights", "ConvNeXt_Small_Weights", "ConvNeXt_Large_Weights"]. |
arch |
Optional[dict]
|
(Default is Tiny architecture config. No need to provide if model_type is provided) depths: (List(int)) Number of layers in each block. Default: [3, 3, 9, 3]. channels: (List(int)) Number of channels in each block. Default: [96, 192, 384, 768]. |
model_type |
str
|
(str) One of the ConvNext architecture types: ["tiny", "small", "base", "large"]. Default: "tiny". |
stem_patch_kernel |
int
|
(int) Size of the convolutional kernels in the stem layer. Default is 4. |
stem_patch_stride |
int
|
(int) Convolutional stride in the stem layer. Default is 2. |
in_channels |
int
|
(int) Number of input channels. Default is 1. |
kernel_size |
int
|
(int) Size of the convolutional kernels. Default is 3. |
filters_rate |
float
|
(float) Factor to adjust the number of filters per block. Default is 2. |
convs_per_block |
int
|
(int) Number of convolutional layers per block. Default is 2. |
up_interpolate |
bool
|
(bool) If True, use bilinear interpolation instead of transposed convolutions for upsampling. Interpolation is faster but transposed convolutions may be able to learn richer or more complex upsampling to recover details from higher scales. Default: True. |
output_stride |
int
|
(int) The stride of the output confidence maps relative to the input image. This is the reciprocal of the resolution, e.g., an output stride of 2 results in confidence maps that are 0.5x the size of the input. Increasing this value can considerably speed up model performance and decrease memory requirements, at the cost of decreased spatial resolution. |
max_stride |
int
|
Factor by which input image size is reduced through the layers.
This is always |
Methods:
| Name | Description |
|---|---|
validate_pre_trained_weights |
Validate pre_trained_weights. |
Source code in sleap_nn/config/model_config.py
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 | |
validate_pre_trained_weights(value)
¶
Validate pre_trained_weights.
Check: convnext_weights are one of ( "ConvNeXt_Base_Weights", "ConvNeXt_Tiny_Weights", "ConvNeXt_Small_Weights", "ConvNeXt_Large_Weights", )
Source code in sleap_nn/config/model_config.py
ConvNextConfig
¶
Convnext configuration for backbone.
Attributes:
| Name | Type | Description |
|---|---|---|
pre_trained_weights |
Optional[str]
|
(str) Pretrained weights file name supported only for ConvNext backbones. For ConvNext, one of ["ConvNeXt_Base_Weights", "ConvNeXt_Tiny_Weights", "ConvNeXt_Small_Weights", "ConvNeXt_Large_Weights"]. |
arch |
Optional[dict]
|
(Default is Tiny architecture config. No need to provide if model_type is provided)
depths: (List[int]) Number of layers in each block. Default: |
model_type |
str
|
(str) One of the ConvNext architecture types: ["tiny", "small", "base", "large"]. Default: |
stem_patch_kernel |
int
|
(int) Size of the convolutional kernels in the stem layer. Default: |
stem_patch_stride |
int
|
(int) Convolutional stride in the stem layer. Default: |
in_channels |
int
|
(int) Number of input channels. Default: |
kernel_size |
int
|
(int) Size of the convolutional kernels. Default: |
filters_rate |
float
|
(float) Factor to adjust the number of filters per block. Default: |
convs_per_block |
int
|
(int) Number of convolutional layers per block. Default: |
up_interpolate |
bool
|
(bool) If True, use bilinear interpolation instead of transposed convolutions for upsampling. Interpolation is faster but transposed convolutions may be able to learn richer or more complex upsampling to recover details from higher scales. Default: |
output_stride |
int
|
(int) The stride of the output confidence maps relative to the input image. This is the reciprocal of the resolution, e.g., an output stride of 2 results in confidence maps that are 0.5x the size of the input. Increasing this value can considerably speed up model performance and decrease memory requirements, at the cost of decreased spatial resolution. Default: |
max_stride |
int
|
(int) Factor by which input image size is reduced through the layers. This is always |
Methods:
| Name | Description |
|---|---|
validate_pre_trained_weights |
Validate pre_trained_weights. |
Source code in sleap_nn/config/model_config.py
validate_pre_trained_weights(value)
¶
Validate pre_trained_weights.
Check: convnext_weights are one of ( "ConvNeXt_Base_Weights", "ConvNeXt_Tiny_Weights", "ConvNeXt_Small_Weights", "ConvNeXt_Large_Weights", )
Source code in sleap_nn/config/model_config.py
ConvNextLargeConfig
¶
Bases: ConvNextConfig
Convnext configuration for backbone.
Attributes:
| Name | Type | Description |
|---|---|---|
pre_trained_weights |
Optional[str]
|
(str) Pretrained weights file name supported only for ConvNext backbones. For ConvNext, one of ["ConvNeXt_Base_Weights", "ConvNeXt_Tiny_Weights", "ConvNeXt_Small_Weights", "ConvNeXt_Large_Weights"]. |
arch |
Optional[dict]
|
(Default is Tiny architecture config. No need to provide if model_type is provided) depths: (List(int)) Number of layers in each block. Default: [3, 3, 9, 3]. channels: (List(int)) Number of channels in each block. Default: [96, 192, 384, 768]. |
model_type |
str
|
(str) One of the ConvNext architecture types: ["tiny", "small", "base", "large"]. Default: "tiny". |
stem_patch_kernel |
int
|
(int) Size of the convolutional kernels in the stem layer. Default is 4. |
stem_patch_stride |
int
|
(int) Convolutional stride in the stem layer. Default is 2. |
in_channels |
int
|
(int) Number of input channels. Default is 1. |
kernel_size |
int
|
(int) Size of the convolutional kernels. Default is 3. |
filters_rate |
float
|
(float) Factor to adjust the number of filters per block. Default is 2. |
convs_per_block |
int
|
(int) Number of convolutional layers per block. Default is 2. |
up_interpolate |
bool
|
(bool) If True, use bilinear interpolation instead of transposed convolutions for upsampling. Interpolation is faster but transposed convolutions may be able to learn richer or more complex upsampling to recover details from higher scales. Default: True. |
output_stride |
int
|
(int) The stride of the output confidence maps relative to the input image. This is the reciprocal of the resolution, e.g., an output stride of 2 results in confidence maps that are 0.5x the size of the input. Increasing this value can considerably speed up model performance and decrease memory requirements, at the cost of decreased spatial resolution. |
max_stride |
int
|
Factor by which input image size is reduced through the layers.
This is always |
Methods:
| Name | Description |
|---|---|
validate_pre_trained_weights |
Validate pre_trained_weights. |
Source code in sleap_nn/config/model_config.py
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 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | |
validate_pre_trained_weights(value)
¶
Validate pre_trained_weights.
Check: convnext_weights are one of ( "ConvNeXt_Base_Weights", "ConvNeXt_Tiny_Weights", "ConvNeXt_Small_Weights", "ConvNeXt_Large_Weights", )
Source code in sleap_nn/config/model_config.py
ConvNextSmallConfig
¶
Bases: ConvNextConfig
Convnext configuration for backbone.
Attributes:
| Name | Type | Description |
|---|---|---|
pre_trained_weights |
Optional[str]
|
(str) Pretrained weights file name supported only for ConvNext backbones. For ConvNext, one of ["ConvNeXt_Base_Weights", "ConvNeXt_Tiny_Weights", "ConvNeXt_Small_Weights", "ConvNeXt_Large_Weights"]. |
arch |
Optional[dict]
|
(Default is Tiny architecture config. No need to provide if model_type is provided) depths: (List(int)) Number of layers in each block. Default: [3, 3, 9, 3]. channels: (List(int)) Number of channels in each block. Default: [96, 192, 384, 768]. |
model_type |
str
|
(str) One of the ConvNext architecture types: ["tiny", "small", "base", "large"]. Default: "tiny". |
stem_patch_kernel |
int
|
(int) Size of the convolutional kernels in the stem layer. Default is 4. |
stem_patch_stride |
int
|
(int) Convolutional stride in the stem layer. Default is 2. |
in_channels |
int
|
(int) Number of input channels. Default is 1. |
kernel_size |
int
|
(int) Size of the convolutional kernels. Default is 3. |
filters_rate |
float
|
(float) Factor to adjust the number of filters per block. Default is 2. |
convs_per_block |
int
|
(int) Number of convolutional layers per block. Default is 2. |
up_interpolate |
bool
|
(bool) If True, use bilinear interpolation instead of transposed convolutions for upsampling. Interpolation is faster but transposed convolutions may be able to learn richer or more complex upsampling to recover details from higher scales. Default: True. |
output_stride |
int
|
(int) The stride of the output confidence maps relative to the input image. This is the reciprocal of the resolution, e.g., an output stride of 2 results in confidence maps that are 0.5x the size of the input. Increasing this value can considerably speed up model performance and decrease memory requirements, at the cost of decreased spatial resolution. |
max_stride |
int
|
Factor by which input image size is reduced through the layers.
This is always |
Methods:
| Name | Description |
|---|---|
validate_pre_trained_weights |
Validate pre_trained_weights. |
Source code in sleap_nn/config/model_config.py
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 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
validate_pre_trained_weights(value)
¶
Validate pre_trained_weights.
Check: convnext_weights are one of ( "ConvNeXt_Base_Weights", "ConvNeXt_Tiny_Weights", "ConvNeXt_Small_Weights", "ConvNeXt_Large_Weights", )
Source code in sleap_nn/config/model_config.py
HeadConfig
¶
Configurations related to the model output head type.
Only one attribute of this class can be set, which defines the model output type.
Attributes:
| Name | Type | Description |
|---|---|---|
single_instance |
Optional[SingleInstanceConfig]
|
An instance of |
centroid |
Optional[CentroidConfig]
|
An instance of |
centered_instance |
Optional[CenteredInstanceConfig]
|
An instance of |
bottomup |
Optional[BottomUpConfig]
|
An instance of |
multi_class_bottomup |
Optional[BottomUpMultiClassConfig]
|
An instance of |
multi_class_topdown |
Optional[TopDownCenteredInstanceMultiClassConfig]
|
An instance of |
bottomup_segmentation |
Optional[BottomUpSegmentationConfig]
|
An instance of |
centered_instance_segmentation |
Optional[CenteredInstanceSegmentationConfig]
|
An instance of
|
semantic_segmentation |
Optional[SemanticSegmentationConfig]
|
An instance of |
Source code in sleap_nn/config/model_config.py
InstanceCenterConfig
¶
Configuration for the instance center heatmap head.
This config is used exclusively by the bottomup_segmentation head; it does
not affect centroid (CentroidConfMapsConfig.sigma) or bottom-up pose
(BottomUpConfMapsConfig) models.
Attributes:
| Name | Type | Description |
|---|---|---|
sigma |
float
|
(float) Standard deviation of the Gaussian distribution used to generate center heatmaps, in pixels at original image resolution. Default: 4.0. Caveat: 4.0 was validated empirically on mice only (compact bodies; it cut learned center over-detection from 60.75 to 14.2 peaks/frame relative to the old default of 10.0, which over-fires badly on elongated bodies). It is the better general default than 10.0, but the optimal value is dataset-dependent: elongated/large animals may want a larger sigma, tiny animals smaller. The target Gaussian is always isotropic (anisotropic targets were tested and performed worse). Because this is a per-head config field, users can tune it per dataset without affecting any other model type. |
output_stride |
int
|
(int) The stride of the output center heatmaps relative to the input image. Default: 2. |
loss_weight |
float
|
(float) Scalar float used to weigh the loss term for this head during training. Default: 1.0. |
Source code in sleap_nn/config/model_config.py
ModelConfig
¶
Configurations related to model architecture.
Attributes:
| Name | Type | Description |
|---|---|---|
init_weights |
str
|
(str) model weights initialization method. "default" uses kaiming uniform initialization and "xavier" uses Xavier initialization method. |
pretrained_backbone_weights |
Optional[str]
|
Path of the |
pretrained_head_weights |
Optional[str]
|
Path of the |
backbone_config |
BackboneConfig
|
initialize either UNetConfig, ConvNextConfig, or SwinTConfig based on input from backbone_type |
head_configs |
HeadConfig
|
(Dict) Dictionary with the following keys having head configs for the model to be trained. Note: Configs should be provided only for the model to train and others should be None |
total_params |
Optional[int]
|
(int) Total number of parameters in the model. This is automatically computed when the training starts. |
Source code in sleap_nn/config/model_config.py
PAFConfig
¶
PAF configuration map.
Attributes:
| Name | Type | Description |
|---|---|---|
edges |
Optional[List[List[str]]]
|
(List[str]) None if edges from sio.Labels file can be used directly. Note: Only for 'PartAffinityFieldsHead'. List of indices (src, dest) that form an edge. |
sigma |
float
|
(float) Spread of the Gaussian distribution of the confidence maps as a scalar float. Smaller values are more precise but may be difficult to learn as they have a lower density within the image space. Larger values are easier to learn but are less precise with respect to the peak coordinate. This spread is in units of pixels of the model input image, i.e., the image resolution after any input scaling is applied. |
output_stride |
int
|
(int) The stride of the output confidence maps relative to the input image. This is the reciprocal of the resolution, e.g., an output stride of 2 results in confidence maps that are 0.5x the size of the input. Increasing this value can considerably speed up model performance and decrease memory requirements, at the cost of decreased spatial resolution. |
loss_weight |
Optional[float]
|
(float) Scalar float used to weigh the loss term for this head during training. Increase this to encourage the optimization to focus on improving this specific output in multi-head models. |
Source code in sleap_nn/config/model_config.py
PretrainedConfig
¶
Configuration for an external pretrained backbone (HuggingFace).
Reuses an external pretrained image encoder (ConvNeXtV2, ResNet, Swinv2,
DINOv2, ...) as the model backbone via transformers AutoBackbone. See
sleap_nn.architectures.pretrained.PretrainedBackbone for the two
integration surfaces (hierarchical decoder vs. encoder-only pooled).
Attributes:
| Name | Type | Description |
|---|---|---|
source |
str
|
(str) Backbone source. Only |
model_name |
str
|
(str) HuggingFace model id, e.g.
|
weights |
bool
|
(bool) If |
mode |
str
|
(str) One of |
freeze |
bool
|
(bool) If |
revision |
Optional[str]
|
(str) Optional HuggingFace revision (commit sha / tag) to pin for
reproducibility. Default: |
normalize |
bool
|
(bool) If |
image_mean |
Optional[List[float]]
|
(List[float]) Optional explicit per-channel mean (length 3). If
|
image_std |
Optional[List[float]]
|
(List[float]) Optional explicit per-channel std (length 3).
Default: |
out_indices |
Optional[List[int]]
|
(List[int]) Optional explicit stage indices to tap (Case A).
If |
in_channels |
int
|
(int) Number of input channels the stem expects. Pretrained
stems are 3-channel; grayscale is replicated upstream. Default: |
filters_rate |
float
|
(float) Decoder filter growth factor (Case A). Default: |
convs_per_block |
int
|
(int) Refinement convs per decoder block (Case A).
Default: |
kernel_size |
int
|
(int) Decoder conv kernel size (Case A). Default: |
up_interpolate |
bool
|
(bool) Bilinear upsampling (vs. transposed conv) in the
decoder (Case A). Default: |
output_stride |
int
|
(int) Stride of the finest decoder output (Case A).
Default: |
max_stride |
int
|
(int) Deepest stride the encoder reaches ( |
Source code in sleap_nn/config/model_config.py
1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 | |
SegmentationHeadConfig
¶
Configuration for the foreground segmentation head.
Shared by bottomup_segmentation and semantic_segmentation (both a
plain foreground head). The loss / target knobs default to the historical
behavior, so an unset config trains exactly as before.
Attributes:
| Name | Type | Description |
|---|---|---|
output_stride |
int
|
(int) The stride of the output segmentation maps relative to the
input image. Default: 2. Setting |
loss_weight |
float
|
(float) Scalar float used to weigh the loss term for this head during training. Default: 1.0. |
bce_weight |
float
|
(float) Weight of the BCE term in the bce-dice foreground loss. Default: 0.5. Tilt toward Dice (e.g. 0.3 BCE / 0.7 Dice) to reduce the easy-background/thick-object dominance for thin foreground. |
dice_weight |
float
|
(float) Weight of the Dice term in the bce-dice loss. Default: 0.5. |
bce_pos_weight |
Optional[float]
|
(Optional[float]) Positive-class weight for the BCE term. For
thin/rare foreground (<1% of pixels), a value >1 (e.g. ~5-20) up-weights
the foreground so the head stays confident on faint thin structures.
|
target_maxpool |
bool
|
(bool) Downsample the foreground target with max-pool
semantics (any foreground pixel in a stride cell -> foreground) instead of
area-average + 0.5 threshold. Default: |
Source code in sleap_nn/config/model_config.py
SemanticSegmentationConfig
¶
Head config for whole-frame semantic (foreground) segmentation models.
A single foreground-mask head predicting one binary foreground/background mask
over the whole frame — no instance grouping, no center/offset heads. It is
the whole-frame analog of centered_instance_segmentation (which runs the
same fg-only SegmentationHead on a centroid crop) and the group-free
sibling of bottomup_segmentation (which adds center + offset heads to group
the foreground into instances). Tiling-compatible.
Reuses the bottom-up SegmentationHeadConfig leaf (output_stride +
loss_weight); it carries no anchor_part because there is no crop.
Source code in sleap_nn/config/model_config.py
SingleInstanceConfMapsConfig
¶
Single Instance configuration map.
Attributes:
| Name | Type | Description |
|---|---|---|
part_names |
Optional[List[str]]
|
(List[str]) None if nodes from sio.Labels file can be used directly. Else provide 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. If not specified, all body parts in the skeleton will be used. This config does not apply for 'PartAffinityFieldsHead'. |
sigma |
float
|
(float) Spread of the Gaussian distribution of the confidence maps as a scalar float. Smaller values are more precise but may be difficult to learn as they have a lower density within the image space. Larger values are easier to learn but are less precise with respect to the peak coordinate. This spread is in units of pixels of the model input image, i.e., the image resolution after any input scaling is applied. |
output_stride |
int
|
(int) The stride of the output confidence maps relative to the input image. This is the reciprocal of the resolution, e.g., an output stride of 2 results in confidence maps that are 0.5x the size of the input. Increasing this value can considerably speed up model performance and decrease memory requirements, at the cost of decreased spatial resolution. |
Source code in sleap_nn/config/model_config.py
SingleInstanceConfig
¶
SwinTBaseConfig
¶
Bases: SwinTConfig
SwinT configuration for backbone.
Attributes:
| Name | Type | Description |
|---|---|---|
pre_trained_weights |
Optional[str]
|
(str) Pretrained weights file name supported only for SwinT backbones. For SwinT, one of ["Swin_T_Weights", "Swin_S_Weights", "Swin_B_Weights"]. |
model_type |
str
|
(str) One of the SwinT architecture types: ["tiny", "small", "base"]. Default: |
arch |
Optional[dict]
|
Dictionary of embed dimension, depths and number of heads in each layer. Default is "Tiny architecture". {'embed': 96, 'depths': [2,2,6,2], 'channels':[3, 6, 12, 24]}. Default: |
max_stride |
int
|
(int) Factor by which input image size is reduced through the layers. This is always |
patch_size |
int
|
(int) Patch size for the stem layer of SwinT. Default: |
stem_patch_stride |
int
|
(int) Stride for the patch. Default: |
window_size |
int
|
(int) Window size. Default: |
in_channels |
int
|
(int) Number of input channels. Default: |
kernel_size |
int
|
(int) Size of the convolutional kernels. Default: |
filters_rate |
float
|
(float) Factor to adjust the number of filters per block. Default: |
convs_per_block |
int
|
(int) Number of convolutional layers per block. Default: |
up_interpolate |
bool
|
(bool) If True, use bilinear interpolation instead of transposed convolutions for upsampling. Interpolation is faster but transposed convolutions may be able to learn richer or more complex upsampling to recover details from higher scales. Default: |
output_stride |
int
|
(int) The stride of the output confidence maps relative to the input image. This is the reciprocal of the resolution, e.g., an output stride of 2 results in confidence maps that are 0.5x the size of the input. Increasing this value can considerably speed up model performance and decrease memory requirements, at the cost of decreased spatial resolution. Default: |
Methods:
| Name | Description |
|---|---|
validate_model_type |
Validate model_type. |
validate_pre_trained_weights |
Validate pre_trained_weights. |
Source code in sleap_nn/config/model_config.py
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 | |
validate_model_type(value)
¶
Validate model_type.
Ensure model_type is one of "tiny", "small", or "base".
Source code in sleap_nn/config/model_config.py
validate_pre_trained_weights(value)
¶
Validate pre_trained_weights.
Check: swint_weights are one of ( "Swin_T_Weights", "Swin_S_Weights", "Swin_B_Weights" )
Source code in sleap_nn/config/model_config.py
SwinTConfig
¶
SwinT configuration (tiny) for backbone.
Attributes:
| Name | Type | Description |
|---|---|---|
pre_trained_weights |
Optional[str]
|
(str) Pretrained weights file name supported only for SwinT backbones. For SwinT, one of ["Swin_T_Weights", "Swin_S_Weights", "Swin_B_Weights"]. |
model_type |
str
|
(str) One of the SwinT architecture types: ["tiny", "small", "base"]. Default: |
arch |
Optional[dict]
|
Dictionary of embed dimension, depths and number of heads in each layer. Default is "Tiny architecture". {'embed': 96, 'depths': [2,2,6,2], 'channels':[3, 6, 12, 24]}. Default: |
max_stride |
int
|
(int) Factor by which input image size is reduced through the layers. This is always |
patch_size |
int
|
(int) Patch size for the stem layer of SwinT. Default: |
stem_patch_stride |
int
|
(int) Stride for the patch. Default: |
window_size |
int
|
(int) Window size. Default: |
in_channels |
int
|
(int) Number of input channels. Default: |
kernel_size |
int
|
(int) Size of the convolutional kernels. Default: |
filters_rate |
float
|
(float) Factor to adjust the number of filters per block. Default: |
convs_per_block |
int
|
(int) Number of convolutional layers per block. Default: |
up_interpolate |
bool
|
(bool) If True, use bilinear interpolation instead of transposed convolutions for upsampling. Interpolation is faster but transposed convolutions may be able to learn richer or more complex upsampling to recover details from higher scales. Default: |
output_stride |
int
|
(int) The stride of the output confidence maps relative to the input image. This is the reciprocal of the resolution, e.g., an output stride of 2 results in confidence maps that are 0.5x the size of the input. Increasing this value can considerably speed up model performance and decrease memory requirements, at the cost of decreased spatial resolution. Default: |
Methods:
| Name | Description |
|---|---|
validate_model_type |
Validate model_type. |
validate_pre_trained_weights |
Validate pre_trained_weights. |
Source code in sleap_nn/config/model_config.py
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 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 | |
validate_model_type(value)
¶
Validate model_type.
Ensure model_type is one of "tiny", "small", or "base".
Source code in sleap_nn/config/model_config.py
validate_pre_trained_weights(value)
¶
Validate pre_trained_weights.
Check: swint_weights are one of ( "Swin_T_Weights", "Swin_S_Weights", "Swin_B_Weights" )
Source code in sleap_nn/config/model_config.py
SwinTSmallConfig
¶
Bases: SwinTConfig
SwinT configuration (small) for backbone.
Attributes:
| Name | Type | Description |
|---|---|---|
pre_trained_weights |
Optional[str]
|
(str) Pretrained weights file name supported only for SwinT backbones. For SwinT, one of ["Swin_T_Weights", "Swin_S_Weights", "Swin_B_Weights"]. |
model_type |
str
|
(str) One of the SwinT architecture types: ["tiny", "small", "base"]. Default: |
arch |
Optional[dict]
|
Dictionary of embed dimension, depths and number of heads in each layer. Default is "Tiny architecture". {'embed': 96, 'depths': [2,2,6,2], 'channels':[3, 6, 12, 24]}. Default: |
max_stride |
int
|
(int) Factor by which input image size is reduced through the layers. This is always |
patch_size |
int
|
(int) Patch size for the stem layer of SwinT. Default: |
stem_patch_stride |
int
|
(int) Stride for the patch. Default: |
window_size |
int
|
(int) Window size. Default: |
in_channels |
int
|
(int) Number of input channels. Default: |
kernel_size |
int
|
(int) Size of the convolutional kernels. Default: |
filters_rate |
float
|
(float) Factor to adjust the number of filters per block. Default: |
convs_per_block |
int
|
(int) Number of convolutional layers per block. Default: |
up_interpolate |
bool
|
(bool) If True, use bilinear interpolation instead of transposed convolutions for upsampling. Interpolation is faster but transposed convolutions may be able to learn richer or more complex upsampling to recover details from higher scales. Default: |
output_stride |
int
|
(int) The stride of the output confidence maps relative to the input image. This is the reciprocal of the resolution, e.g., an output stride of 2 results in confidence maps that are 0.5x the size of the input. Increasing this value can considerably speed up model performance and decrease memory requirements, at the cost of decreased spatial resolution. Default: |
Methods:
| Name | Description |
|---|---|
validate_model_type |
Validate model_type. |
validate_pre_trained_weights |
Validate pre_trained_weights. |
Source code in sleap_nn/config/model_config.py
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 | |
validate_model_type(value)
¶
Validate model_type.
Ensure model_type is one of "tiny", "small", or "base".
Source code in sleap_nn/config/model_config.py
validate_pre_trained_weights(value)
¶
Validate pre_trained_weights.
Check: swint_weights are one of ( "Swin_T_Weights", "Swin_S_Weights", "Swin_B_Weights" )
Source code in sleap_nn/config/model_config.py
TopDownCenteredInstanceMultiClassConfig
¶
Head config for TopDown centered instance ID models.
Source code in sleap_nn/config/model_config.py
UNetConfig
¶
UNet config for backbone.
Attributes:
| Name | Type | Description |
|---|---|---|
in_channels |
int
|
(int) Number of input channels. Default: |
kernel_size |
int
|
(int) Size of the convolutional kernels. Default: |
filters |
int
|
(int) Base number of filters in the network. Default: |
filters_rate |
float
|
(float) Factor to adjust the number of filters per block. Default: |
max_stride |
int
|
(int) Scalar integer specifying the maximum stride that the image must be divisible by. Default: |
stem_stride |
Optional[int]
|
(int) If not None, will create additional "down" blocks for initial downsampling based on the stride. These will be configured identically to the down blocks below. Default: |
middle_block |
bool
|
(bool) If True, add an additional block at the end of the encoder. Default: |
up_interpolate |
bool
|
(bool) If True, use bilinear interpolation instead of transposed convolutions for upsampling. Interpolation is faster but transposed convolutions may be able to learn richer or more complex upsampling to recover details from higher scales. Default: |
stacks |
int
|
(int) Number of upsampling blocks in the decoder. Default: |
convs_per_block |
int
|
(int) Number of convolutional layers per block. Default: |
output_stride |
int
|
(int) The stride of the output confidence maps relative to the input image. This is the reciprocal of the resolution, e.g., an output stride of 2 results in confidence maps that are 0.5x the size of the input. Increasing this value can considerably speed up model performance and decrease memory requirements, at the cost of decreased spatial resolution. Default: |
Source code in sleap_nn/config/model_config.py
UNetLargeRFConfig
¶
Bases: UNetConfig
UNet config for backbone with large receptive field.
Attributes:
| Name | Type | Description |
|---|---|---|
in_channels |
int
|
(int) Number of input channels. Default: |
kernel_size |
int
|
(int) Size of the convolutional kernels. Default: |
filters |
int
|
(int) Base number of filters in the network. Default: |
filters_rate |
float
|
(float) Factor to adjust the number of filters per block. Default: |
max_stride |
int
|
(int) Scalar integer specifying the maximum stride that the image must be divisible by. Default: |
stem_stride |
Optional[int]
|
(int) If not None, will create additional "down" blocks for initial downsampling based on the stride. These will be configured identically to the down blocks below. Default: |
middle_block |
bool
|
(bool) If True, add an additional block at the end of the encoder. Default: |
up_interpolate |
bool
|
(bool) If True, use bilinear interpolation instead of transposed convolutions for upsampling. Interpolation is faster but transposed convolutions may be able to learn richer or more complex upsampling to recover details from higher scales. Default: |
stacks |
int
|
(int) Number of upsampling blocks in the decoder. Default: |
convs_per_block |
int
|
(int) Number of convolutional layers per block. Default: |
output_stride |
int
|
(int) The stride of the output confidence maps relative to the input image. This is the reciprocal of the resolution, e.g., an output stride of 2 results in confidence maps that are 0.5x the size of the input. Increasing this value can considerably speed up model performance and decrease memory requirements, at the cost of decreased spatial resolution. Default: |
Source code in sleap_nn/config/model_config.py
UNetMediumRFConfig
¶
Bases: UNetConfig
UNet config for backbone with medium receptive field.
Attributes:
| Name | Type | Description |
|---|---|---|
in_channels |
int
|
(int) Number of input channels. Default: |
kernel_size |
int
|
(int) Size of the convolutional kernels. Default: |
filters |
int
|
(int) Base number of filters in the network. Default: |
filters_rate |
float
|
(float) Factor to adjust the number of filters per block. Default: |
max_stride |
int
|
(int) Scalar integer specifying the maximum stride that the image must be divisible by. Default: |
stem_stride |
Optional[int]
|
(int) If not None, will create additional "down" blocks for initial downsampling based on the stride. These will be configured identically to the down blocks below. Default: |
middle_block |
bool
|
(bool) If True, add an additional block at the end of the encoder. Default: |
up_interpolate |
bool
|
(bool) If True, use bilinear interpolation instead of transposed convolutions for upsampling. Interpolation is faster but transposed convolutions may be able to learn richer or more complex upsampling to recover details from higher scales. Default: |
stacks |
int
|
(int) Number of upsampling blocks in the decoder. Default: |
convs_per_block |
int
|
(int) Number of convolutional layers per block. Default: |
output_stride |
int
|
(int) The stride of the output confidence maps relative to the input image. This is the reciprocal of the resolution, e.g., an output stride of 2 results in confidence maps that are 0.5x the size of the input. Increasing this value can considerably speed up model performance and decrease memory requirements, at the cost of decreased spatial resolution. Default: |
Source code in sleap_nn/config/model_config.py
model_mapper(legacy_config)
¶
Map the legacy model configuration to the new model configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
legacy_config
|
dict
|
A dictionary containing the legacy model configuration. |
required |
Returns:
| Type | Description |
|---|---|
ModelConfig
|
An instance of |
Source code in sleap_nn/config/model_config.py
1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 | |