Skip to content

wrapper

orchard.core.metadata.wrapper

Pydantic Wrappers for Multi-Domain Dataset Registries.

Type-safe, validated access to dataset domains organized by task type (classification, detection) and resolution. Each wrapper subclass merges its own domain registries while avoiding global metadata overwrites.

Use get_registry(resolution, task_type) to obtain the correct wrapper.

DatasetRegistryWrapper

Bases: BaseModel

Base wrapper for dataset registries.

Provides resolution validation, deep-copied access, and the get_dataset lookup method. Subclasses define which domain registries are available.

Attributes:

Name Type Description
resolution int

Target dataset resolution.

registry dict[str, DatasetMetadata]

Deep-copied metadata registry for the selected resolution.

get_dataset(name)

Retrieve a DatasetMetadata entry by name.

Parameters:

Name Type Description Default
name str

Dataset identifier.

required

Returns:

Type Description
DatasetMetadata

Deep copy of the matching DatasetMetadata.

Raises:

Type Description
KeyError

If dataset not found in registry.

Source code in orchard/core/metadata/wrapper.py
def get_dataset(self, name: str) -> DatasetMetadata:
    """
    Retrieve a DatasetMetadata entry by name.

    Args:
        name: Dataset identifier.

    Returns:
        Deep copy of the matching DatasetMetadata.

    Raises:
        KeyError: If dataset not found in registry.
    """
    if name not in self.registry:
        available = list(self.registry.keys())
        raise KeyError(f"Dataset '{name}' not found. Available: {available}")

    return copy.deepcopy(self.registry[name])

ClassificationRegistryWrapper

Bases: DatasetRegistryWrapper

Registry wrapper for classification datasets (medical, space, benchmark).

DetectionRegistryWrapper

Bases: DatasetRegistryWrapper

Registry wrapper for detection datasets.

get_registry(resolution, task_type='classification')

Factory function to obtain the correct registry wrapper for a task.

Parameters:

Name Type Description Default
resolution int

Target image resolution.

required
task_type str

"classification" or "detection".

'classification'

Returns:

Type Description
DatasetRegistryWrapper

Registry wrapper with datasets available for the given task and resolution.

Raises:

Type Description
ValueError

If task_type is not "classification" or "detection".

Source code in orchard/core/metadata/wrapper.py
def get_registry(
    resolution: int,
    task_type: str = "classification",
) -> DatasetRegistryWrapper:
    """
    Factory function to obtain the correct registry wrapper for a task.

    Args:
        resolution: Target image resolution.
        task_type: ``"classification"`` or ``"detection"``.

    Returns:
        Registry wrapper with datasets available for the given task and resolution.

    Raises:
        ValueError: If ``task_type`` is not ``"classification"`` or ``"detection"``.
    """
    if task_type == "detection":
        return DetectionRegistryWrapper(resolution=resolution)
    if task_type != "classification":
        raise ValueError(
            f"Unknown task_type: {task_type!r}. Expected 'classification' or 'detection'."
        )
    return ClassificationRegistryWrapper(resolution=resolution)