Refactor `ctd_conditions` / `conditions_provider` + add `ConditionsConfig` + fix `InferenceConfig` (#3387)
* refactor ctd config (inference)
Refactor type InferenceConfig.conditions with ConditionsConfig union
Replace the untyped `dict[str, Any] | None` conditions field with a proper
typed hierarchy: `ConditionsConfig` base class with `ConditionsFileConfig`
(filepath only) and `ConditionsModelConfig` (direct paths or DLC shuffle
shorthand) subclasses. A `ConditionsConfig.build()` classmethod normalizes
any raw YAML input (str, Path, dict) into the correct subtype.
- Add `config/ctd_conditions.py` with the three config classes
- Update `InferenceConfig.conditions` to `ConditionsModelConfig | ConditionsFileConfig | None`
with a `mode="before"` field validator calling `ConditionsConfig.build()`
- Refactor `get_condition_provider()` to accept `ConditionsModelConfig | dict`
and use `ConditionsConfig.build()` instead of ad-hoc dict inspection
- Fix bug in `CondFromModel.__init__`: `snapshot_path` was incorrectly
assigned `Path(config_path)` instead of `Path(snapshot_path)`
* refactor data/ctd.py: replace get_loader_and_snapshot with helper.
* refactor data/ctd.py: remove ABC CondProvider
CondProvider was denoted as abstract class, but was no abstract in practice since both subclasses call its methods. The helper is a cleaner way to achieve the same.
* refactor ConditionsConfig: add build from shuffle
* refactor ConditionsConfig: clean up build constructors
* Add affords_bu_inference property to ConditionsConfig
* refactor callers with ctd_conditions: use normalized ConditionsConfig if applicable
* refactor data/ctd.py and apis/ctd.py
- remove CondFromModel: it was just a config. Now replaced with ConditionsModelConfig
- remove get_condition_provider: it was just a wrapper to initialize CondFromModel, which is now centralized in ConditionsModelConfig
* add ConditionsShuffleConfig and `resolve_from_conditions()`
Add ConditionsConfig subtype for unresolved shuffle-references. And hook-up ModelConfig.resolve_from_conditions().
* refactor analyze_images: clean normalization of ctd_conditions
- Only when task is COND_TOP_DOWN.
- falsey values "", {} etc should not silently fall back to model_cfg.inference.conditions
* refactor analyze_image_folder (only accept resolved cond_provider)
This function is just used internally, does not require a project config and uses resolved model snapshots etc,. Since not all ConditionsConfigurations (e.g. shuffle) can be resolved without a projectconfig, and since resolution already happens in upstream funcitons it is more clean to strictly accept ConditionsModelConfig here.
* refactor analyze_videos and analyze_images (strict ConditionsShuffleConfig or ConditionsModelConfig, not ConditionsFileConfig.
* add missing shuffle literal
* Fix load_conditions_for_evaluation: add support for Typed ConditionsConfigs
* Improve docstrings and function signatures
Correctly reflect the available subtypes of ConditionsConfig for analysis or live inference
* add tests for ctd conditions configurations
* remove unused property "affords_bu_inference"
* refactor tests_ctd_conditions, improve variable names and fix circular assertion
* update test_ctd_conditions
- remove circular assertion
- add missing tests (e.g. DLCLoader injects)
- format parametrized input as pytest.param for more clarity J
Jaap de Ruyter van Steveninck committed
6a181fd283f318c100da7353d3bb48bc5e23601c
Parent: 785bcda
Committed by GitHub <noreply@github.com>
on 7/20/2026, 12:15:25 PM