deeplabcut.core.config.utils
Centralized helpers for reading, writing, and creating configuration files (YAML).
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. |
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.