Refactor ctd_conditions / conditions_provider + add ConditionsConfig + fix InferenceConfig - #3387
Conversation
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)`
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.
- 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
ctd_conditions / conditions_provider + add ConditionsConfig + fix InferenceConfigctd_conditions / conditions_provider + add ConditionsConfig + fix InferenceConfig
Add ConditionsConfig subtype for unresolved shuffle-references. And hook-up ModelConfig.resolve_from_conditions().
|
Edit |
There was a problem hiding this comment.
I think this is a very good start, and indeed good to harden this a bit.
There are still a few things that may be worth clarifying:
- Should we wrap the old CondFromModel with a deprecated constructor that routes to the new builder? Or not worth it as internal API/too much effort for the payoff
resolve_from_conditionsis very nice to expose capabilities from the schema. It may be worth making the supported capabilities of each condition source more explicit, either in the documentation or through routing in the code, to make future refactors easier
Adding tests (which might already be done or planned) would be very helpful too.
- Only when task is COND_TOP_DOWN.
- falsey values "", {} etc should not silently fall back to model_cfg.inference.conditions
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.
…onfig or ConditionsModelConfig, not ConditionsFileConfig.
|
@deruyter92 I'm fixing the fast lane in another PR, sorry for the CI fails |
Correctly reflect the available subtypes of ConditionsConfig for analysis or live inference
- remove circular assertion - add missing tests (e.g. DLCLoader injects) - format parametrized input as pytest.param for more clarity
|
@C-Achard thanks again for your initial review. I've addressed your comments and made some extra adjustments:
We should probably discuss whether it is worth to add the option of using precomputed conditions via Let me know if you think this adjustment would still be worth it, or if you think that caching is sufficient for now. |
C-Achard
left a comment
There was a problem hiding this comment.
Thanks for all the updates!
Let's leave it out then |
Issues
This PR addresses two issues with the way conditions are specified for inference with a BUCTD model:
dictwas supported.CondProviderin pose_estimation_pytorch/data/ctd.py was slightly incorrect and misleading:CondFromFileandCondFromModelserve a different thing (either a provider that can read conditions from a file, or just a config object that still needs downstream loading of the BU model).Implementation
ConditionsConfigurationschema with two subclassesConditionsFileConfigandConditionsModelConfigto solve the oversimplified schema design.CondProvideris refactored: onlyCondFromFileis kept, as it literally provides conditions from a file. TheCondFromModelconfiguration class is replaced withConditionsModelConfig.ConditionsConfigor their raw arguments, and normalized + validated at the beginning.