deeplabcut.pose_estimation_pytorch.config.make_pose_config
Methods to create the configuration files for PyTorch DeepLabCut models.
Functions:
| Name | Description |
|---|---|
add_detector |
Adds a detector to a model. |
add_identity_head |
Adds an identity head to a model. |
add_metadata |
Adds metadata to a pytorch pose configuration. |
add_unique_bodypart_head |
Adds a unique bodypart head to a model. |
create_backbone_with_heatmap_model |
Creates a simple heatmap pose estimation model, composed of a backbone and a head |
create_backbone_with_paf_model |
Creates a pose estimation model, composed of a backbone and a head predicting |
make_basic_project_config |
Creates a basic configuration dict that can be used to create model configs. |
make_pytorch_pose_config |
Creates a PyTorch pose configuration file for a DeepLabCut project. |
make_pytorch_test_config |
Creates the test configuration for a model. |
add_detector
add_detector(configs_dir: Path, config: dict, num_individuals: int, detector_type: str | None = None) -> dict
Adds a detector to a model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Path
|
path to the DeepLabCut "configs" directory |
required |
|
dict
|
model configuration to update |
required |
|
int
|
the maximum number of individuals the model should detect |
required |
|
str | None
|
the type of detector to use (if None, uses |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
the model configuration with an added detector config |
Source code in deeplabcut/pose_estimation_pytorch/config/make_pose_config.py
add_identity_head
add_identity_head(configs_dir: Path, config: dict, num_individuals: int, backbone_output_channels: int) -> dict
Adds an identity head to a model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Path
|
path to the DeepLabCut "configs" directory |
required |
|
dict
|
model configuration to update |
required |
|
int
|
the number of individuals to re-identify |
required |
|
int
|
the number of channels output by the model backbone |
required |
Returns:
| Type | Description |
|---|---|
dict
|
the configuration with an added identity head |
Source code in deeplabcut/pose_estimation_pytorch/config/make_pose_config.py
add_metadata
Adds metadata to a pytorch pose configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict
|
the project configuration |
required |
|
dict
|
the pytorch pose configuration |
required |
|
str | Path
|
the path where the pytorch pose configuration will be saved |
required |
Returns:
| Type | Description |
|---|---|
dict
|
the configuration with a |
Source code in deeplabcut/pose_estimation_pytorch/config/make_pose_config.py
add_unique_bodypart_head
add_unique_bodypart_head(
configs_dir: Path, config: dict, num_unique_bodyparts: int, backbone_output_channels: int
) -> dict
Adds a unique bodypart head to a model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Path
|
path to the DeepLabCut "configs" directory |
required |
|
dict
|
model configuration to update |
required |
|
int
|
the number of unique bodyparts to detect |
required |
|
int
|
the number of channels output by the model backbone |
required |
Returns:
| Type | Description |
|---|---|
dict
|
the configuration with an added unique bodypart head |
Source code in deeplabcut/pose_estimation_pytorch/config/make_pose_config.py
create_backbone_with_heatmap_model
create_backbone_with_heatmap_model(
configs_dir: Path, net_type: str, multianimal_project: bool, bodyparts: list[str], top_down: bool
) -> dict
Creates a simple heatmap pose estimation model, composed of a backbone and a head predicting heatmaps and location refinement maps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Path
|
path to the DeepLabCut "configs" directory |
required |
|
str
|
the type of backbone to create the model with (e.g., resnet_50) |
required |
|
bool
|
whether this model is created for a multi-animal project |
required |
|
list[str]
|
the bodyparts to detect |
required |
|
bool
|
whether the model will be associated to a detector to form a top-down pose estimation model |
required |
Returns:
| Type | Description |
|---|---|
dict
|
the backbone + heatmap model configuration |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the model is being created for a multi-animal project but the head won't be associated with a detector (heatmaps can only predict bodyparts for a single individual). |
Source code in deeplabcut/pose_estimation_pytorch/config/make_pose_config.py
create_backbone_with_paf_model
create_backbone_with_paf_model(
configs_dir: Path, net_type: str, num_individuals: int, bodyparts: list[str], paf_parameters: dict
) -> dict
Creates a pose estimation model, composed of a backbone and a head predicting heatmaps, location refinement maps and part affinity fields for multi-animal pose estimation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Path
|
path to the DeepLabCut "configs" directory |
required |
|
str
|
the type of backbone to create the model with (e.g., resnet_50) |
required |
|
int
|
the maximum number of individuals in a frame |
required |
|
list[str]
|
the bodyparts to detect |
required |
|
dict
|
the parameters for the PAF |
required |
Returns:
| Type | Description |
|---|---|
dict
|
the backbone + heatmap, location refinement, PAF model configuration |
Source code in deeplabcut/pose_estimation_pytorch/config/make_pose_config.py
make_basic_project_config
make_basic_project_config(
dataset_path: Path | str, bodyparts: list[str], max_individuals: int, multi_animal: bool = True
) -> dict
Creates a basic configuration dict that can be used to create model configs.
This should be used to create the project_config given to
make_pytorch_pose_config for non-DeepLabCut projects (e.g. when creating a
configuration file for a model that will be trained on a COCO dataset).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Path | str
|
The path to the dataset for which the config will be created. |
required |
|
list[str]
|
The bodyparts labeled for individuals in the dataset. |
required |
|
int
|
The maximum number of individuals to detect in a single image. |
required |
|
bool
|
Whether multiple animals can be present in an image. |
True
|
Returns:
| Type | Description |
|---|---|
dict
|
The created project configuration dict that can be given to
|
Examples:
Creating a pytorch_config for a ResNet50 backbone with a part-affinity head (
as multi_animal=True and top_down=False)
>>> import deeplabcut.pose_estimation_pytorch as pep
>>> project_config = pep.config.make_basic_project_config(
>>> dataset_path="/path/coco",
>>> bodyparts=["nose", "left_eye", "right_eye"],
>>> max_individuals=12,
>>> multi_animal=True,
>>> )
>>> model_config = pep.config.make_pytorch_pose_config(
>>> project_config=project_config,
>>> pose_config_path="/path/coco/models/resnet50/pytorch_config.yaml",
>>> net_type="resnet_50",
>>> top_down=False,
>>> save=True,
>>> )
Creating a pytorch_config for a ResNet50 backbone with a simple heatmap head
(as the project is single-animal):
>>> import deeplabcut.pose_estimation_pytorch as pep
>>> project_config = pep.config.make_basic_project_config(
>>> dataset_path="/path/coco",
>>> bodyparts=["nose", "left_eye", "right_eye"],
>>> max_individuals=1,
>>> multi_animal=False,
>>> )
>>> model_config = pep.config.make_pytorch_pose_config(
>>> project_config=project_config,
>>> pose_config_path="/path/coco/models/resnet50/pytorch_config.yaml",
>>> net_type="resnet_50",
>>> top_down=False,
>>> save=True,
>>> )
Source code in deeplabcut/pose_estimation_pytorch/config/make_pose_config.py
make_pytorch_pose_config
make_pytorch_pose_config(
project_config: dict,
pose_config_path: str | Path,
net_type: str | None = None,
top_down: bool = False,
detector_type: str | None = None,
weight_init: WeightInitialization | None = None,
save: bool = False,
ctd_conditions: int | str | Path | tuple[int, str] | tuple[int, int] | None = None,
) -> dict
Creates a PyTorch pose configuration file for a DeepLabCut project.
The base/ folder contains default configurations, such as data augmentations or heatmap heads (that can be used to predict pose or identity based on visual features). These files are used to create pose model configurations.
All available backbone configurations are stored in the backbones/ folder. - any backbone can be a single animal model with a heatmap head added on top - any backbone can be a top-down model with a detector and a heatmap head - any backbone can be a bottom-up model with a detector and a heatmap + PAF head
All other model architectures have their own folders, with different variants
available. Top-down model architectures must specify method: TD in their
configuration files, from which this method adds a backbone configuration.
Placeholder values (such as num_bodyparts or num_individuals) are filled in
based on the project config file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict
|
the DeepLabCut project config |
required |
|
str | Path
|
the path where the pytorch pose configuration will be saved |
required |
|
str | None
|
the architecture of the desired pose estimation model |
None
|
|
bool
|
when the net_type is a backbone, whether to create a top-down model by associating a detector to the pose model. Required for multi-animal projects when net_type is a backbone (as a backbone + heatmap head can only predict pose for single individuals). |
False
|
|
str | None
|
for top-down pose models, the architecture of the desired object detection model |
None
|
|
WeightInitialization | None
|
Specify how model weights should be initialized. If None, ImageNet pretrained weights from Timm will be loaded when training. |
None
|
|
bool
|
Whether to save the model configuration file to the |
False
|
|
int | str | Path | tuple[int, str] | tuple[int, int] | None
|
int | str | Path | tuple[int, str] | tuple[int, int] , optional, default = None, If using a conditional-top-down (CTD) net_type, this argument needs to be specified. It defines the conditions that will be used with the CTD model. It can be either: * A shuffle number (ctd_conditions: int), which must correspond to a bottom-up (BU) network type. * A predictions file path (ctd_conditions: string | Path), which must correspond to a .json or .h5 predictions file. * A shuffle number and a particular snapshot (ctd_conditions: tuple[int, str] | tuple[int, int]), which respectively correspond to a bottom-up (BU) network type and a particular snapshot name or index. |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
the PyTorch pose configuration file |
Source code in deeplabcut/pose_estimation_pytorch/config/make_pose_config.py
32 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 | |
make_pytorch_test_config
make_pytorch_test_config(model_config: dict, test_config_path: str | Path, save: bool = False) -> dict
Creates the test configuration for a model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict
|
The PyTorch config for the model. |
required |
|
str | Path
|
The path of the test config |
required |
|
bool
|
Whether to save the test config to |
False
|
Returns:
| Type | Description |
|---|---|
dict
|
The test configuration file. |