Skip to content

helpers

orchard.tasks.detection.helpers

Shared Helpers for Detection Adapters.

Internal utilities used by multiple detection adapters.

to_cpu(d)

Move all tensor values in a dict to CPU.

Parameters:

Name Type Description Default
d dict[str, Any]

Dict with tensor values (e.g. detection predictions or targets).

required

Returns:

Type Description
dict[str, Any]

New dict with all tensors moved to CPU; non-tensor values unchanged.

Source code in orchard/tasks/detection/helpers.py
def to_cpu(d: dict[str, Any]) -> dict[str, Any]:
    """
    Move all tensor values in a dict to CPU.

    Args:
        d: Dict with tensor values (e.g. detection predictions or targets).

    Returns:
        New dict with all tensors moved to CPU; non-tensor values unchanged.
    """
    return {k: v.cpu() if isinstance(v, torch.Tensor) else v for k, v in d.items()}