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
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 |
|
__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'. |
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' |
required |
head_config
|
DictConfig
|
A config for the head. |
required |
Returns:
Type | Description |
---|---|
Head
|
nn.Module: An instance of the requested head. |