model
sleap_nn.architectures.model
¶
This module defines the main SLEAP model class for defining a trainable model.
This is a higher level wrapper around nn.Module that holds all the configuration
parameters required to construct the actual model. This allows for easy querying of the
model configuration without actually instantiating the model itself.
Classes:
| Name | Description |
|---|---|
Model |
Model creates a model consisting of a backbone and head. |
Functions:
| Name | Description |
|---|---|
get_backbone |
Get a backbone model |
get_head |
Get a head |
Model
¶
Bases: Module
Model creates a model consisting of a backbone and head.
Attributes:
| Name | Type | Description |
|---|---|---|
backbone_type |
Backbone type. One of |
|
backbone_config |
An |
|
head_configs |
An |
|
model_type |
Type of the model. One of |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the backbone and head based on the backbone_config. |
forward |
Forward pass through the model. |
from_config |
Create the model from a config dictionary. |
Source code in sleap_nn/architectures/model.py
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 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 | |
__init__(backbone_type, backbone_config, head_configs, model_type)
¶
Initialize the backbone and head based on the backbone_config.
Source code in sleap_nn/architectures/model.py
forward(x)
¶
Forward pass through the model.
Source code in sleap_nn/architectures/model.py
from_config(backbone_type, backbone_config, head_configs, model_type)
classmethod
¶
Create the model from a config dictionary.
Source code in sleap_nn/architectures/model.py
get_backbone(backbone, backbone_config)
¶
Get a backbone model nn.Module based on the provided name.
This function returns an instance of a PyTorch nn.Module
corresponding to the given backbone name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backbone
|
str
|
Name of the backbone. Supported values are 'unet', 'convnext', 'swint', and 'pretrained' (external HuggingFace backbone). |
required |
backbone_config
|
DictConfig
|
A config for the backbone. |
required |
Returns:
| Type | Description |
|---|---|
Module
|
nn.Module: An instance of the requested backbone model. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the provided backbone name is not one of the supported values. |
Source code in sleap_nn/architectures/model.py
get_head(model_type, head_config)
¶
Get a head nn.Module based on the provided name.
This function returns an instance of a PyTorch nn.Module
corresponding to the given head name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_type
|
str
|
Name of the head. Supported values are - 'single_instance' - 'centroid' - 'centered_instance' - 'bottomup' - 'multi_class_bottomup' - 'multi_class_topdown' - 'bottomup_segmentation' - 'centered_instance_segmentation' - 'embedding' |
required |
head_config
|
DictConfig
|
A config for the head. |
required |
Returns:
| Type | Description |
|---|---|
Head
|
nn.Module: An instance of the requested head. |
Source code in sleap_nn/architectures/model.py
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 | |