Visitar URL original
Refactor `ctd_conditions` / `conditions_provider` + add `ConditionsConfig` + fix `InferenceConfig` by deruyter92 · Pull Request #3387 · DeepLabCut/DeepLabCut · GitHub
Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
dfaeabb
refactor ctd config (inference)
deruyter92 Jul 9, 2026
d698c85
refactor data/ctd.py: replace get_loader_and_snapshot with helper.
deruyter92 Jul 10, 2026
c13f25f
refactor data/ctd.py: remove ABC CondProvider
deruyter92 Jul 10, 2026
986ac8d
refactor ConditionsConfig: add build from shuffle
deruyter92 Jul 10, 2026
73f0d77
refactor ConditionsConfig: clean up build constructors
deruyter92 Jul 10, 2026
77807e2
Add affords_bu_inference property to ConditionsConfig
deruyter92 Jul 10, 2026
67229b9
refactor callers with ctd_conditions: use normalized ConditionsConfig…
deruyter92 Jul 10, 2026
0660100
refactor data/ctd.py and apis/ctd.py
deruyter92 Jul 10, 2026
8553294
add ConditionsShuffleConfig and `resolve_from_conditions()`
deruyter92 Jul 10, 2026
3ebd7b0
refactor analyze_images: clean normalization of ctd_conditions
deruyter92 Jul 14, 2026
1ed7e61
refactor analyze_image_folder (only accept resolved cond_provider)
deruyter92 Jul 14, 2026
35cf90a
refactor analyze_videos and analyze_images (strict ConditionsShuffleC…
deruyter92 Jul 14, 2026
38cca93
add missing shuffle literal
deruyter92 Jul 14, 2026
b87c970
Fix load_conditions_for_evaluation: add support for Typed ConditionsC…
deruyter92 Jul 14, 2026
3592b16
Improve docstrings and function signatures
deruyter92 Jul 14, 2026
03036d9
add tests for ctd conditions configurations
deruyter92 Jul 14, 2026
047dfa4
remove unused property "affords_bu_inference"
deruyter92 Jul 14, 2026
c37fc07
refactor tests_ctd_conditions, improve variable names and fix circula…
deruyter92 Jul 14, 2026
9642add
update test_ctd_conditions
deruyter92 Jul 14, 2026
7a36f4a
Merge branch 'main' into jaap/fix_ctd_conditions_config
deruyter92 Jul 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
deruyter92 committed Jul 10, 2026
commit c13f25ff25774586b4167753489bff064a204ece
89 changes: 4 additions & 85 deletions deeplabcut/pose_estimation_pytorch/data/ctd.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import json
import pickle
from abc import ABC, abstractmethod
from pathlib import Path

import numpy as np
Expand Down Expand Up @@ -83,49 +82,7 @@ def resolve_bu_shuffle(
return loader, bu_snapshot


class CondProvider(ABC):
"""A class providing conditions for a CTD model."""

@classmethod
@abstractmethod
def get_loader_and_snapshot(
cls,
config: str | Path,
shuffle: int,
trainset_index: int = 0,
modelprefix: str = "",
snapshot: str | None = None,
snapshot_index: int | None = None,
) -> tuple[DLCLoader, Snapshot]:
"""Creates a DLCLoader for the BU shuffle and the path to conditions snapshot.

Args:
config: Path to the DeepLabCut project config, or the project config itself
trainset_index: The index of the TrainingsetFraction for which to load data
shuffle: The index of the shuffle for which to load data.
modelprefix: The modelprefix for the shuffle.
snapshot: The name of the snapshot to use.
snapshot_index: The index of the snapshot to use. If `snapshot` is
provided, the `snapshot_index` is not used.

Returns:
loader: The DLCLoader for the BU shuffle.
snapshot: The BU Snapshot to use for conditions.

Raises:
ValueError: If the given shuffle is not for a BU model.
"""
return resolve_bu_shuffle(
config=config,
shuffle=shuffle,
trainset_index=trainset_index,
modelprefix=modelprefix,
snapshot=snapshot,
snapshot_index=snapshot_index,
)


class CondFromFile(CondProvider):
class CondFromFile:
"""A class providing conditions for a CTD model from a file.

Args:
Expand All @@ -144,7 +101,7 @@ def __init__(
) -> None:
if filepath is None:
# Load the conditions filepath from the Shuffle
bu_loader, bu_snapshot = self.get_loader_and_snapshot(**kwargs)
bu_loader, bu_snapshot = resolve_bu_shuffle(**kwargs)
bu_scorer = bu_loader.scorer(bu_snapshot)
filepath = bu_loader.evaluation_folder / f"{bu_scorer}.h5"
if not filepath.exists():
Expand All @@ -161,25 +118,6 @@ def __init__(

self.filepath = filepath

@classmethod
def get_loader_and_snapshot(
cls,
config: str | Path,
shuffle: int,
trainset_index: int = 0,
modelprefix: str = "",
snapshot: str | None = None,
snapshot_index: int | None = None,
) -> tuple[DLCLoader, Snapshot]:
return super().get_loader_and_snapshot(
config=config,
shuffle=shuffle,
trainset_index=trainset_index,
modelprefix=modelprefix,
snapshot=snapshot,
snapshot_index=snapshot_index,
)

def load_conditions(
self,
images: list[str] | None = None,
Expand Down Expand Up @@ -479,7 +417,7 @@ def load_conditions_pickle(filepath: str | Path) -> list[np.ndarray]:
return parsed


class CondFromModel(CondProvider):
class CondFromModel:
"""A class providing conditions for a CTD model from a BU model.

Attributes:
Expand Down Expand Up @@ -511,7 +449,7 @@ def __init__(
config_path = Path(config_path)
snapshot_path = Path(snapshot_path)
elif "config" in kwargs and "shuffle" in kwargs:
bu_loader, snapshot = self.get_loader_and_snapshot(**kwargs)
bu_loader, snapshot = resolve_bu_shuffle(**kwargs)
config_path = bu_loader.model_config_path
snapshot_path = snapshot.path
if scorer is None:
Expand All @@ -520,22 +458,3 @@ def __init__(
self.config_path = config_path
self.snapshot_path = snapshot_path
self.scorer = scorer

@classmethod
def get_loader_and_snapshot(
cls,
config: str | Path,
shuffle: int,
trainset_index: int = 0,
modelprefix: str = "",
snapshot: str | None = None,
snapshot_index: int | None = None,
) -> tuple[DLCLoader, Snapshot]:
return super().get_loader_and_snapshot(
config=config,
shuffle=shuffle,
trainset_index=trainset_index,
modelprefix=modelprefix,
snapshot=snapshot,
snapshot_index=snapshot_index,
)