Skip to content

[dev] Refactor config constructors via build() methods - #3369

Merged
deruyter92 merged 26 commits into
jaap/C7_config_cleanup_simplifyfrom
jaap/C7d_refactor_constructors
Jun 18, 2026
Merged

[dev] Refactor config constructors via build() methods#3369
deruyter92 merged 26 commits into
jaap/C7_config_cleanup_simplifyfrom
jaap/C7d_refactor_constructors

Conversation

@deruyter92

Copy link
Copy Markdown
Collaborator

The construction of configs used to be a bit of a spaghetti of loading yamls, adjusting fields midway, and then updating them once more in the API calls, such as train_network.

The structured configs refactor improved this a bit, but there was a mixed state with validation halfway construction, requiring the need for nullable fields and moving a lot back and forth between dicts and types.

This PR aims to move construction of configs for a specific deeplabcut project or deeplabcut net type to a canonical build() method on the structured configs themselves.

The construction is now always split in two steps. E.g. for PoseConfig:

  1. build the defaults dictionary from the yaml (given a net_type, derived from ProjectConfig + build args)
  2. construct a validated PoseConfig from the defaults

API calls can still update the PoseConfig with overrides (e.g. train_network), but these overrides are never required: the validated PoseConfig is always considered a fully initialized model that can be used downstream.

- Split enums into separate file
- Split PoseMetadata into separate file
- Split PafParamters into separate file
- Add canonical build methods for structured configs: e.g. build from project config
- build entire default dict for net_type from the yaml file, before validation.
- deprecate `make_pytorch_test_config`, `make_pytorch_pose_config` and `make_basic_project_config`.
@deruyter92
deruyter92 requested a review from C-Achard June 15, 2026 15:32
@deruyter92 deruyter92 self-assigned this Jun 15, 2026
@C-Achard
C-Achard requested a review from Copilot June 15, 2026 18:53

@C-Achard C-Achard left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some initial comments

Comment thread deeplabcut/core/config/project_config.py
Comment thread deeplabcut/pose_estimation_pytorch/config/pose.py Outdated
Comment thread deeplabcut/pose_estimation_pytorch/config/pose.py Outdated
Comment thread deeplabcut/pose_estimation_pytorch/config/pose.py Outdated
Comment thread deeplabcut/pose_estimation_pytorch/config/pose.py
Comment thread deeplabcut/pose_estimation_pytorch/config/make_pose_config.py
Comment thread deeplabcut/pose_estimation_pytorch/config/make_pose_config.py Outdated
Comment thread deeplabcut/pose_estimation_pytorch/modelzoo/config.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors PyTorch pose config construction into canonical build()/build_for_*() classmethods on the structured config models, aiming to ensure configs are fully-initialized/validated at construction time and to deprecate older factory/helper functions.

Changes:

  • Introduces PoseConfig.build(...), PoseConfig.build_for_superanimal_inference(...), and PoseConfig.build_for_superanimal_finetune(...) as canonical constructors.
  • Extracts config components into dedicated models/utilities (PoseMetadata, PAFParameters, and config.enums) and updates config-building utilities accordingly.
  • Deprecates legacy config factory functions and adapts modelzoo/config writing paths to the new constructors.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
deeplabcut/pose_estimation_pytorch/modelzoo/utils.py Deprecates load_super_animal_config and adjusts SuperAnimal config updating behavior.
deeplabcut/pose_estimation_pytorch/modelzoo/config.py Adds SuperAnimal metadata/inference/finetune config builders and updates YAML writing.
deeplabcut/pose_estimation_pytorch/config/pose.py Adds PoseConfig.build*() constructors and moves toward canonical build flow.
deeplabcut/pose_estimation_pytorch/config/paf_parameters.py Introduces a typed PAF parameter model and builder.
deeplabcut/pose_estimation_pytorch/config/metadata.py Introduces a typed Pose metadata model and builders (including SuperAnimal).
deeplabcut/pose_estimation_pytorch/config/make_pose_config.py Deprecates legacy factory functions and refactors default-building helpers for structured config construction.
deeplabcut/pose_estimation_pytorch/config/enums.py Extracts shared enums into a dedicated module.
deeplabcut/pose_estimation_pytorch/config/init.py Re-exports enums/models and updates public API surface for deprecated factories.
deeplabcut/create_project/modelzoo.py Updates modelzoo project creation to use new metadata/config construction.
deeplabcut/core/config/project_config.py Adds ProjectConfig.bodyparts_list helper for animal-count-agnostic bodypart access.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread deeplabcut/pose_estimation_pytorch/config/pose.py
Comment thread deeplabcut/pose_estimation_pytorch/config/pose.py
Comment thread deeplabcut/pose_estimation_pytorch/config/pose.py Outdated
Comment thread deeplabcut/pose_estimation_pytorch/config/make_pose_config.py
Comment thread deeplabcut/pose_estimation_pytorch/config/make_pose_config.py Outdated
Comment thread deeplabcut/pose_estimation_pytorch/config/make_pose_config.py
Comment thread deeplabcut/pose_estimation_pytorch/modelzoo/config.py
Comment thread deeplabcut/create_project/modelzoo.py Outdated
…td shuffle.

The documented primary workflow is: set conditions at shuffle / dataset creation, not defer until inference. This was not reflected in the test, and surfaced with the new structured configs.

This commit makes the test in line with recommended workflow in API docstring; Config docs; BUCTD COLAB notebook; and GUI. -> ctd_conditions are passed at dataset creation time. making the shuffle a fully complete artefact, rather than somthing that requires patching in later API calls.
@deruyter92

Copy link
Copy Markdown
Collaborator Author

merging into #3354 and rebasing everything on main (facilitates easier review as well)

@deruyter92
deruyter92 marked this pull request as ready for review June 18, 2026 09:29
@deruyter92
deruyter92 merged commit 723b1df into jaap/C7_config_cleanup_simplify Jun 18, 2026
3 checks passed
@deruyter92
deruyter92 deleted the jaap/C7d_refactor_constructors branch June 18, 2026 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants