deeplabcut.pose_estimation_pytorch.models.model
Classes:
| Name | Description |
|---|---|
PoseModel |
A pose estimation model. |
Functions:
| Name | Description |
|---|---|
filter_state_dict |
Filters keys in the state dict for a module to only keep a given prefix. Removes |
PoseModel
Bases: Module
A pose estimation model.
A pose estimation model is composed of a backbone, optionally a neck, and an arbitrary number of heads. Outputs are computed as follows:
Methods:
| Name | Description |
|---|---|
__init__ |
Args: |
build |
Args: |
forward |
Forward pass of the PoseModel. |
get_predictions |
Abstract method for the forward pass of the Predictor. |
get_stride |
Args: |
get_target |
Summary: |
Source code in deeplabcut/pose_estimation_pytorch/models/model.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 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 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 | |
__init__
__init__(cfg: dict, backbone: BaseBackbone, heads: dict[str, BaseHead], neck: BaseNeck | None = None) -> None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict
|
configuration dictionary for the model. |
required |
|
BaseBackbone
|
backbone network architecture. |
required |
|
dict[str, BaseHead]
|
the heads for the model |
required |
|
BaseNeck | None
|
neck network architecture (default is None). Defaults to None. |
None
|
Source code in deeplabcut/pose_estimation_pytorch/models/model.py
build
staticmethod
build(cfg: dict, weight_init: None | WeightInitialization = None, pretrained_backbone: bool = False) -> PoseModel
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict
|
The configuration of the model to build. |
required |
|
None | WeightInitialization
|
How model weights should be initialized. If None, ImageNet pre-trained backbone weights are loaded from Timm. |
None
|
|
bool
|
Whether to load an ImageNet-pretrained weights for the backbone. This should only be set to True when building a model which will be trained on a transfer learning task. |
False
|
Returns:
| Type | Description |
|---|---|
PoseModel
|
the built pose model |
Source code in deeplabcut/pose_estimation_pytorch/models/model.py
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 | |
forward
Forward pass of the PoseModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Tensor
|
input images |
required |
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Tensor]]
|
Outputs of head groups |
Source code in deeplabcut/pose_estimation_pytorch/models/model.py
get_predictions
Abstract method for the forward pass of the Predictor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict[str, dict[str, Tensor]]
|
outputs of the model heads |
required |
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary containing the predictions of each head group |
Source code in deeplabcut/pose_estimation_pytorch/models/model.py
get_stride
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The head for which to get the total stride. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The total stride for the outputs of the head. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If there is no such head. |
Source code in deeplabcut/pose_estimation_pytorch/models/model.py
get_target
Summary: Get targets for model training.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict[str, dict[str, Tensor]]
|
output of each head group |
required |
|
dict
|
dictionary of labels |
required |
Returns:
| Name | Type | Description |
|---|---|---|
targets |
dict[str, dict]
|
dict of the targets for each model head group |
Source code in deeplabcut/pose_estimation_pytorch/models/model.py
filter_state_dict
Filters keys in the state dict for a module to only keep a given prefix. Removes the module from the keys (e.g. for module="backbone", "backbone.stage1.weight" will be converted to "stage1.weight" so the state dict can be loaded into the backbone directly).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict
|
the state dict |
required |
|
str
|
the module to keep, e.g. "backbone" |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Tensor]
|
the filtered state dict, with the module removed from the keys |
Examples:
state_dict = {"backbone.conv.weight": t1, "head.conv.weight": t2} filtered = filter_state_dict(state_dict, "backbone")
filtered =
model.backbone.load_state_dict(filtered)