deeplabcut.core.config
Modules:
| Name | Description |
|---|---|
base_config |
|
project_config |
Project configuration classes for DeepLabCut pose estimation models. |
utils |
Centralized helpers for reading, writing, and creating configuration files (YAML). |
versioning |
Configuration migration system for handling version upgrades and downgrades. |
Classes:
| Name | Description |
|---|---|
DLCBaseConfig |
Pydantic base for DeepLabCut configuration models. |
DLCVersionedConfig |
Top-level configs with schema migration and change tracking. |
ProjectConfig |
Complete project configuration. |
Functions:
| Name | Description |
|---|---|
create_config_template |
Creates a template for config.yaml file. This specific order is preserved while saving as yaml file. |
create_config_template_3d |
Creates a template for config.yaml file for 3d project. This specific order is preserved while saving as yaml file. |
edit_config |
Convenience function to edit and save a config file from a dictionary. |
ensure_plain_config |
Convert typed config arguments into plain Python objects. |
get_yaml_dumper |
Get a ruamel.yaml YAML handler with representers for Enum and Path objects. |
get_yaml_loader |
Get a ruamel.yaml YAML handler with safe mode. |
normalize_for_serialization |
Recursively normalize Paths to strings and Enums to values. |
pretty_print |
Prints a model configuration in a pretty and readable way. |
read_config |
Reads structured config file defining a project. |
read_config_as_dict |
Args: |
resolve_alias |
Resolve a config key to its canonical field name. |
resolve_aliases_in_dict |
Rename deprecated config keys to their canonical names. |
write_config |
Writes a pose configuration file to disk. |
write_config_3d |
Write structured 3D project config file. |
write_config_3d_template |
Write 3D config from pre-built template and YAML instance. |
write_project_config |
Write structured project config file (config.yaml) preserving template order. |
DLCBaseConfig
Bases: BaseModel
Pydantic base for DeepLabCut configuration models.
This class is used to create configuration models for DeepLabCut.
It provides a base class for all configuration models that need YAML/dict I/O
and optional deprecated field names via json_schema_extra["aliases"].
(Use for all nested configs, e.g. pytorch DataConfig, InferenceConfig, etc.)
For project-level schema migration and dirty-field tracking, subclass
DLCVersionedConfig instead.
Features:
- Strict schema (
extra="forbid",validate_assignment=True). - Load and save:
from_yaml,from_dict,from_any,to_yaml,to_dict. - Pretty-print via
print. - Hooks:
_post_yaml_load_updates. - Nested dot-notation via
select. - Dict-like access over declared fields (legacy compatibility).
- In-place bulk updates via
update. - Field aliases from
json_schema_extra.
Methods:
| Name | Description |
|---|---|
resolve_aliases_before_validate |
Resolves aliases to their canonical names. (Normalizes ArgsKwargs |
select |
Select a value from the config using dot notation for nested keys. |
to_commented_map |
Recursively convert the config to a CommentedMap with YAML comments. |
Source code in deeplabcut/core/config/base_config.py
28 29 30 31 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 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 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |
resolve_aliases_before_validate
classmethod
Resolves aliases to their canonical names. (Normalizes ArgsKwargs input to a dict for downstream validation.)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
Raw validator input ( |
required |
Returns:
| Type | Description |
|---|---|
Any
|
A dict with canonical field names when input is ArgsKwargs or dict;
otherwise |
Source code in deeplabcut/core/config/base_config.py
select
Select a value from the config using dot notation for nested keys.
Source code in deeplabcut/core/config/base_config.py
to_commented_map
Recursively convert the config to a CommentedMap with YAML comments.
Source code in deeplabcut/core/config/base_config.py
DLCVersionedConfig
Bases: DLCBaseConfig
Top-level configs with schema migration and change tracking.
Subclass of DLCBaseConfig for project and pose YAML configs such as
ProjectConfig and PoseConfig.
Note
Pydantic runs migrate_before_validate before the base
resolve_aliases_before_validate (child-first order): schema migration
on legacy keys, then alias resolution for the current model.
Additional behavior:
migrate_before_validateupgrades raw dicts toCURRENT_CONFIG_VERSION.- Tracks fields modified after load;
to_yamlcan log changes and mark clean. - Patches
__setattr__once per class to record dirty fields while delegating alias warnings to the base__setattr__.
Source code in deeplabcut/core/config/base_config.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | |
ProjectConfig
Bases: DLCVersionedConfig
Complete project configuration.
Mirrors the structure of the project config.yaml (and metadata in pose config). Field names match the old dictionary keys for round-trip compatibility.
Attributes:
| Name | Type | Description |
|---|---|---|
Task |
str
|
Project task identifier (do not edit). |
scorer |
str
|
Scorer name (do not edit). |
date |
str
|
Project date (do not edit). |
multianimalproject |
bool
|
Whether the project is multi-animal. |
identity |
bool | None
|
Whether identity tracking is enabled (project config.yaml key). |
project_path |
Path
|
Path to the DeepLabCut project. |
pose_config_path |
Path | None
|
Path to the pose configuration file (metadata only). |
engine |
Literal['pytorch', 'tensorflow']
|
Default DeepLabCut engine (e.g. pytorch). |
video_sets |
dict[str, Any]
|
Video set configuration. |
bodyparts |
UniqueStrList | Literal['MULTI!']
|
List of body parts. |
individuals |
UniqueStrList
|
List of individual animal identities (multi-animal). |
uniquebodyparts |
UniqueStrList
|
List of unique body parts (multi-animal project key). |
multianimalbodyparts |
UniqueStrList
|
List of multi-animal body parts (multi-animal key). |
start |
Fraction
|
Fraction of video to start extracting frames. |
stop |
Fraction
|
Fraction of video to stop extracting frames. |
numframes2pick |
NonNegativeInt
|
Number of frames to pick for labeling. |
skeleton |
list[BodypartPair]
|
Skeleton connectivity for plotting. |
skeleton_color |
str
|
Skeleton color for plotting. |
pcutoff |
Fraction
|
Confidence cutoff for plotting. |
dotsize |
NonNegativeInt
|
Dot size for visualization. |
alphavalue |
Fraction
|
Alpha value for visualization. |
colormap |
str
|
Colormap for visualization. |
TrainingFraction |
list[Fraction]
|
Training fractions for dataset splits. |
iteration |
NonNegativeInt | None
|
Training iteration. |
default_net_type |
str
|
Default network architecture. |
default_augmenter |
str | None
|
Default data augmenter. |
default_track_method |
str | None
|
Default tracking method. |
snapshotindex |
Literal['all'] | int
|
Snapshot index for evaluation. |
detector_snapshotindex |
int
|
Detector snapshot index. |
batch_size |
StrictPositiveInt
|
Training batch size. |
detector_batch_size |
StrictPositiveInt
|
Detector batch size. |
cropping |
bool
|
Whether cropping is enabled for analysis. |
x1 |
NonNegativeInt | None
|
Cropping x1 coordinate. |
x2 |
NonNegativeInt | None
|
Cropping x2 coordinate. |
y1 |
NonNegativeInt | None
|
Cropping y1 coordinate. |
y2 |
NonNegativeInt | None
|
Cropping y2 coordinate. |
corner2move2 |
list[NonNegativeInt] | None
|
Refinement corner configuration. |
move2corner |
bool | None
|
Refinement move-to-corner flag. |
SuperAnimalConversionTables |
dict[str, Any] | None
|
Conversion tables for SuperAnimal weights. |
Methods:
| Name | Description |
|---|---|
validate_project_path |
Repair project_path from yaml location; optionally persist. |
Source code in deeplabcut/core/config/project_config.py
31 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 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 | |
validate_project_path
Repair project_path from yaml location; optionally persist.
Source code in deeplabcut/core/config/project_config.py
create_config_template
Creates a template for config.yaml file. This specific order is preserved while saving as yaml file.
Returns:
| Type | Description |
|---|---|
tuple
|
(cfg_file, ruamelFile) for further editing and dumping. |
Source code in deeplabcut/core/config/utils.py
create_config_template_3d
Creates a template for config.yaml file for 3d project. This specific order is preserved while saving as yaml file.
Returns:
| Type | Description |
|---|---|
tuple
|
(cfg_file_3d, ruamelFile_3d) for further editing and dumping. |
Source code in deeplabcut/core/config/utils.py
edit_config
Convenience function to edit and save a config file from a dictionary.
Note
Legacy helper without schema validation. Prefer manipulating and saving the typed config instead (e.g. cfg.update(edits).to_yaml(cfg_path))
Parameters
configname : string String containing the full path of the config file in the project. edits : dict Key–value pairs to edit in config output_name : string, optional (default='') Overwrite the original config.yaml by default. If passed in though, new filename of the edited config.
Examples
config_path = 'my_stellar_lab/dlc/config.yaml'
edits = {'numframes2pick': 5, 'trainingFraction': [0.5, 0.8], 'skeleton': [['a', 'b'], ['b', 'c']]}
deeplabcut.core.config.edit_config(config_path, edits)
Source code in deeplabcut/core/config/utils.py
ensure_plain_config
Convert typed config arguments into plain Python objects.
Any positional or keyword argument that is a DLCBaseConfig is converted to
a plain dict before the decorated function is called.
Source code in deeplabcut/core/config/utils.py
get_yaml_dumper
Get a ruamel.yaml YAML handler with representers for Enum and Path objects.
Source code in deeplabcut/core/config/utils.py
get_yaml_loader
normalize_for_serialization
Recursively normalize Paths to strings and Enums to values.
Source code in deeplabcut/core/config/utils.py
pretty_print
Prints a model configuration in a pretty and readable way.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict
|
the config to print |
required |
|
int
|
the base indent on all keys |
0
|
|
Callable[[str], None] | None
|
custom function to call (simply calls |
None
|
Source code in deeplabcut/core/config/utils.py
read_config
Reads structured config file defining a project.
Applies default values and repairs (engine, detector_snapshotindex, project_path) and writes back if needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path
|
Path to the project configuration file (config.yaml). |
required |
|
bool
|
If True, empty/None values in the YAML are ignored and dataclass defaults are used instead. If False, empty values represent None. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
ProjectConfig
|
The project configuration as a ProjectConfig instance (supports dict-like access). |
Source code in deeplabcut/core/config/utils.py
read_config_as_dict
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path
|
the path to the configuration file to load |
required |
Returns:
| Type | Description |
|---|---|
dict
|
The configuration file with pure Python classes |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
if the config file does not exist |
Source code in deeplabcut/core/config/utils.py
resolve_alias
resolve_alias(name: str, alias_map: dict[str, str], *, warn: bool = True, stacklevel: int = 3) -> str
Resolve a config key to its canonical field name.
Args:
name: Raw key name (alias or canonical).
alias_map: {alias: canonical_name} for deprecated keys.
warn: If True, emit :class:DLCDeprecationWarning when name is an alias.
stacklevel: Passed to :func:warnings.warn for deprecation messages.
Returns:
Canonical field name, or name unchanged if it is not an alias.
Source code in deeplabcut/core/config/utils.py
resolve_aliases_in_dict
resolve_aliases_in_dict(
cfg_dict: dict, alias_map: dict[str, str], *, target: str = "config", warn: bool = True, stacklevel: int = 3
) -> dict
Rename deprecated config keys to their canonical names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict
|
Raw configuration mapping (e.g. from YAML). |
required |
|
dict[str, str]
|
|
required |
|
str
|
Config class name shown in errors. |
'config'
|
|
int
|
Passed to :func: |
3
|
Returns:
| Type | Description |
|---|---|
dict
|
A new dict with alias keys replaced by canonical names. Unchanged if
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If multiple keys resolve to the same canonical field name |
Source code in deeplabcut/core/config/utils.py
write_config
Writes a pose configuration file to disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path
|
the path where the config should be saved |
required |
|
dict
|
the config to save |
required |
|
bool
|
whether to overwrite the file if it already exists |
True
|
Source code in deeplabcut/core/config/utils.py
write_config_3d
Write structured 3D project config file.
Source code in deeplabcut/core/config/utils.py
write_config_3d_template
write_config_3d_template(projconfigfile: str | Path, cfg_file_3d: dict, ruamelFile_3d: YAML) -> None
Write 3D config from pre-built template and YAML instance.
Source code in deeplabcut/core/config/utils.py
write_project_config
Write structured project config file (config.yaml) preserving template order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path
|
Path to the project configuration file (config.yaml). |
required |
|
dict | ProjectConfig
|
The project configuration to write (requires ProjectConfig schema). |
required |
Note
Validates before writing when possible, unvalidated legacy dump on failure; This may not round-trip via read_config for non-conformant legacy configurations.