deeplabcut.pose_estimation_pytorch.models.necks.layers
Classes:
| Name | Description |
|---|---|
Attention |
Attention block module. |
FeedForward |
FeedForward block module. |
PreNorm |
PreNorm block module. |
Residual |
Residual block module. |
TransformerLayer |
TransformerLayer block module. |
Attention
Bases: Module
Attention block module.
This module implements the attention mechanism in the transformer layers.
Attributes:
| Name | Type | Description |
|---|---|---|
dim |
Dimension of the input tensor. |
|
heads |
Number of attention heads. Defaults to 8. |
|
dropout |
Dropout rate. Defaults to 0.0. |
|
num_keypoints |
Number of keypoints. Defaults to None. |
|
scale_with_head |
Scale attention with the number of heads. Defaults to False. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the Attention block. |
forward |
Forward pass through the Attention block. |
Source code in deeplabcut/pose_estimation_pytorch/models/necks/layers.py
__init__
__init__(dim: int, heads: int = 8, dropout: float = 0.0, num_keypoints: int = None, scale_with_head: bool = False)
Initialize the Attention block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int
|
Dimension of the input tensor. |
required |
|
int
|
Number of attention heads. Defaults to 8. |
8
|
|
float
|
Dropout rate. Defaults to 0.0. |
0.0
|
|
int
|
Number of keypoints. Defaults to None. |
None
|
|
bool
|
Scale attention with the number of heads. Defaults to False. |
False
|
Source code in deeplabcut/pose_estimation_pytorch/models/necks/layers.py
forward
Forward pass through the Attention block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Tensor
|
Input tensor. |
required |
|
Tensor
|
Attention mask. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
|
Output tensor. |
Source code in deeplabcut/pose_estimation_pytorch/models/necks/layers.py
FeedForward
Bases: Module
FeedForward block module.
This module implements the feedforward layer in the transformer layers.
Attributes:
| Name | Type | Description |
|---|---|---|
dim |
Dimension of the input tensor. |
|
hidden_dim |
Dimension of the hidden layer. |
|
dropout |
Dropout rate. Defaults to 0.0. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the FeedForward block. |
forward |
Forward pass through the FeedForward block. |
Source code in deeplabcut/pose_estimation_pytorch/models/necks/layers.py
__init__
Initialize the FeedForward block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int
|
Dimension of the input tensor. |
required |
|
int
|
Dimension of the hidden layer. |
required |
|
float
|
Dropout rate. Defaults to 0.0. |
0.0
|
Source code in deeplabcut/pose_estimation_pytorch/models/necks/layers.py
forward
Forward pass through the FeedForward block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Tensor
|
Input tensor. |
required |
Returns:
| Type | Description |
|---|---|
|
Output tensor. |
PreNorm
Bases: Module
PreNorm block module.
This module implements pre-normalization for the transformer layers.
Attributes:
| Name | Type | Description |
|---|---|---|
dim |
Dimension of the input tensor. |
|
fn |
The function to apply after normalization. |
|
fusion_factor |
Fusion factor for layer normalization. Defaults to 1. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the PreNorm block. |
forward |
Forward pass through the PreNorm block. |
Source code in deeplabcut/pose_estimation_pytorch/models/necks/layers.py
__init__
Initialize the PreNorm block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int
|
Dimension of the input tensor. |
required |
|
Module
|
The function to apply after normalization. |
required |
|
int
|
Fusion factor for layer normalization. Defaults to 1. |
1
|
Source code in deeplabcut/pose_estimation_pytorch/models/necks/layers.py
forward
Forward pass through the PreNorm block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Input tensor. |
required | |
|
Additional keyword arguments for the function. |
{}
|
Returns:
| Type | Description |
|---|---|
|
Output tensor. |
Source code in deeplabcut/pose_estimation_pytorch/models/necks/layers.py
Residual
Bases: Module
Residual block module.
This module implements a residual block for the transformer layers.
Attributes:
| Name | Type | Description |
|---|---|---|
fn |
The function to apply in the residual block. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the Residual block. |
forward |
Forward pass through the Residual block. |
Source code in deeplabcut/pose_estimation_pytorch/models/necks/layers.py
__init__
Initialize the Residual block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Module
|
The function to apply in the residual block. |
required |
forward
Forward pass through the Residual block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Tensor
|
Input tensor. |
required |
|
Additional keyword arguments for the function. |
{}
|
Returns:
| Type | Description |
|---|---|
|
Output tensor. |
Source code in deeplabcut/pose_estimation_pytorch/models/necks/layers.py
TransformerLayer
Bases: Module
TransformerLayer block module.
This module implements the Transformer layer in the transformer model.
Attributes:
| Name | Type | Description |
|---|---|---|
dim |
Dimension of the input tensor. |
|
depth |
Depth of the transformer layer. |
|
heads |
Number of attention heads. |
|
mlp_dim |
Dimension of the MLP layer. |
|
dropout |
Dropout rate. |
|
num_keypoints |
Number of keypoints. Defaults to None. |
|
all_attn |
Apply attention to all keypoints. Defaults to False. |
|
scale_with_head |
Scale attention with the number of heads. Defaults to False. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the TransformerLayer block. |
forward |
Forward pass through the TransformerLayer block. |
Source code in deeplabcut/pose_estimation_pytorch/models/necks/layers.py
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 280 281 | |
__init__
__init__(
dim: int,
depth: int,
heads: int,
mlp_dim: int,
dropout: float,
num_keypoints: int = None,
all_attn: bool = False,
scale_with_head: bool = False,
)
Initialize the TransformerLayer block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int
|
Dimension of the input tensor. |
required |
|
int
|
Depth of the transformer layer. |
required |
|
int
|
Number of attention heads. |
required |
|
int
|
Dimension of the MLP layer. |
required |
|
float
|
Dropout rate. |
required |
|
int
|
Number of keypoints. Defaults to None. |
None
|
|
bool
|
Apply attention to all keypoints. Defaults to False. |
False
|
|
bool
|
Scale attention with the number of heads. Defaults to False. |
False
|
Source code in deeplabcut/pose_estimation_pytorch/models/necks/layers.py
forward
Forward pass through the TransformerLayer block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Tensor
|
Input tensor. |
required |
|
Tensor
|
Attention mask. Defaults to None. |
None
|
|
Tensor
|
Positional encoding. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
|
Output tensor. |