Skip to content

Port PoseConfig from DeepLabCut - #48

Open
C-Achard wants to merge 5 commits into
cy/config-versionsfrom
cy/pose-config
Open

C-Achard wants to merge 5 commits into
cy/config-versionsfrom
cy/pose-config

Conversation

@C-Achard

@C-Achard C-Achard commented Dec 4, 2026

Copy link
Copy Markdown
Member

Scope

The schema of DeepLabCut's PyTorch pytorch_config.yaml, copied from DeepLabCut dev at d2bbe028: reading, validating, migrating and writing. Building a config, from DeepLabCut's architecture templates or the model zoo, stays in DeepLabCut. Tests here are DeepLabCut's unit tests for the sub-configs; tests that configs read back as DeepLabCut wrote them are the next PR of this stack.

Motivation

DeepLabCut-live reads the config stored in an exported model without DeepLabCut, and keeps its own copies of the logic that interprets it, including its own fix for DeepLabCut issue 3592 in rtmcc_head.update_input_size. Database ingestion needs to read net types and model metadata without installing DeepLabCut and its training stack.

Main changes

  • dlccore.config.pose holds PoseConfig, DetectorConfig, TestConfig and every sub-config, plus WeightInitialization, which is a field type of the train settings; nothing in it imports DeepLabCut, torch or albumentations.
  • Changes relative to DeepLabCut are limited to imports and removed members, so the copies can be diffed: the build* factories, NetType.is_backbone, alias and available_aliases, the SuperAnimal and shuffle-resolution helpers, PAFParameters.build, and WeightInitialization's legacy and build paths.
  • DataConfig.validate_transforms was removed: it builds the augmentations with albumentations and torch, and returns its input unchanged, so dropping it changes which configs are accepted, not the values read.
  • _match_top_down_crop_to_heads is kept as DeepLabCut has it: on read, it sets top_down_crop to a fixed head input size and reports this to the log only.
  • The PoseConfig migrations are registered in pose.py, as on DeepLabCut's cy/config-from-dlccore.
  • The pydantic floor rises from 2.1 to 2.12, which added Field(exclude_if=...), used by the train settings; DeepLabCut declares the same floor.

Additional context

  • NetType is a closed enum: a model added to DeepLabCut needs a dlccore release before dlccore reads its configs.
  • DeepLabCut's copy is owed a deletion. That side, not in this PR: re-export these classes, turn the build* methods into functions, and run the transforms check where the data loader reads the config, so a bad augmentation still fails before training.
  • For DeepLabCut-live, adopting this adds pydantic and raises its pandas floor from 1.0.1 to dlccore's 2.3.3.
  • A weight_init written before 3.0.0rc5 reads with snapshot_path=None, as it does in DeepLabCut: the legacy path that resolved a SuperAnimal snapshot ran only from WeightInitialization.from_dict, never from a pose config read.
  • ruff's tests/config/*.py exclusion also matched tests/config/pose/; it now names the ported test files, so tests written for dlccore are linted.

@C-Achard C-Achard added this to the Config migration milestone Dec 4, 2026
@C-Achard C-Achard added enhancement New feature or request io: config config.yaml reading, writing and its schema consumer: deeplabcut Needed by or affects DeepLabCut consumer: datajoint Needed by or affects the DataJoint pipeline consumer: live Needed by or affects DeepLabCut-live and its GUI port Copies code from another DeepLabCut repository; the old copy is owed a deletion packaging PRs that modify metadata, dependency declarations, etc used to build and install the project. labels Dec 4, 2026
@C-Achard
C-Achard added this pull request to stack #50 December 4, 2026 15:16
- Copied from DeepLabCut `dev` at d2bbe028, `deeplabcut/pose_estimation_pytorch/config/`: `ctd_conditions`, `data`, `enums`, `logger`, `model`, `paf_parameters`, `runner`. These import nothing beyond pydantic and dlccore's base config.
- Changes relative to DeepLabCut are limited to imports and to removing members that need DeepLabCut, so dlccore can read a `pytorch_config.yaml` without it:
  - `DataConfig` and `DetectorDataConfig`: `validate_transforms`, which builds the augmentations with albumentations and torch. It returns its input unchanged, so dropping it changes which configs are accepted, not the values read.
  - `NetType`: `is_backbone`, `alias` and `available_aliases`, which read DeepLabCut's architecture template folder. `from_alias`, the read path, stays.
  - `PAFParameters`: `build` and `get_paf_parameters`, which prune the graph with `deeplabcut.utils.auxfun_multianimal`.
  - `ConditionsModelConfig`: `from_shuffle` and `resolve_from_conditions`, which resolve a shuffle through DeepLabCut's data loader. Docstrings still name them; they remain DeepLabCut's API.
- `enums.py` and `paf_parameters.py` had no license header in DeepLabCut; they get DeepLabCut's.
- No `__init__.py` yet: `dlccore.config.pose` is a namespace package until the package exports are added.
- Copied from DeepLabCut `dev` at d2bbe028: `pose_estimation_pytorch/config/inference.py` and `metadata.py`, and `core/weight_init.py`, moved to `dlccore/config/pose/weight_init.py` since it is a field type of the pose config's train settings.
- `inference.py` builds on the committed `ctd_conditions`; `metadata.py` needs `ProjectConfig`; `weight_init.py` needs `NDArrayInt` (numpy). None imports DeepLabCut.
- Changes relative to DeepLabCut are limited to imports and to removing members that need DeepLabCut:
  - `PoseMetadata.build_for_superanimal`, which reads the model zoo. `PoseMetadata.build`, which needs only `ProjectConfig`, stays.
  - `WeightInitialization.from_dict`, `from_dict_legacy` and `build`, which resolve SuperAnimal snapshots through the model zoo. `from_dict` is DeepLabCut's override that sends a dict without `snapshot_path` to the legacy path; DeepLabCut's own pose config read validates the nested field directly and never takes it, so reading a stored config gives the same result.
- Copied from DeepLabCut `dev` at d2bbe028, `pose_estimation_pytorch/config/training.py`, unchanged but for imports. `weight_init` now comes from `dlccore.config.pose`.
- Raise the pydantic floor from 2.1 to 2.12: `TrainSettingsConfig.dataloader_kwargs` uses `Field(exclude_if=...)`, added in pydantic 2.12.0b1, to omit empty kwargs when saving. DeepLabCut declares the same floor.
- Copied from DeepLabCut `dev` at d2bbe028, `pose_estimation_pytorch/config/pose.py`: `PoseConfig`, `DetectorConfig` and `TestConfig`. With the schemas already copied, dlccore reads, validates, migrates and writes a `pytorch_config.yaml` without DeepLabCut, so DeepLabCut-live and database ingestion can read trained model configs without installing it.
- Omitted, as they build a config from DeepLabCut's architecture templates or the model zoo: `PoseConfig.build`, `build_for_superanimal_inference`, `build_for_superanimal_finetune` and `DetectorConfig.build`.
- The `PoseConfig` migrations move into `pose.py`, as on DeepLabCut's `cy/config-from-dlccore`, where they register in dlccore's registry. `PoseConfig`'s current version is its entry in `versioning.CURRENT_CONFIG_VERSIONS`.
- `NetType` is a closed enum: a model added to DeepLabCut needs a dlccore release before dlccore reads its configs.
- `dlccore.config.pose` exports the public classes, `WeightInitialization` and `DetectorDataConfig` included; `pose` is listed in `dlccore.config.__all__`.
- From DeepLabCut `dev` at d2bbe028, imports changed: `test_logger_config.py`, `test_runner_config.py`, `test_train_settings_config.py`, and the schema half of `test_ctd_conditions.py`; resolving conditions against a shuffle stays in DeepLabCut.
- ruff's `tests/config/*.py` exclusion also matched `tests/config/pose/`, as `*` crosses `/`. It now names `tests/config/conftest.py`, `tests/config/test_*.py` and the four ported files, so tests written for dlccore are linted.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

consumer: datajoint Needed by or affects the DataJoint pipeline consumer: deeplabcut Needed by or affects DeepLabCut consumer: live Needed by or affects DeepLabCut-live and its GUI enhancement New feature or request io: config config.yaml reading, writing and its schema packaging PRs that modify metadata, dependency declarations, etc used to build and install the project. port Copies code from another DeepLabCut repository; the old copy is owed a deletion

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant