Skip to content

utils

The data utils.

kelp.nn.data.utils.unbind_samples

Reverse of :func:stack_samples.

Useful for turning a mini-batch of samples into a list of samples. These individual samples can then be plotted using a dataset's plot method.

Taken from torchgeo.

Parameters:

Name Type Description Default
sample Dict[Any, Sequence[Any]]

a mini-batch of samples

required

Returns:

Type Description
List[Dict[Any, Any]]

list of samples

Source code in kelp/nn/data/utils.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
def unbind_samples(sample: Dict[Any, Sequence[Any]]) -> List[Dict[Any, Any]]:
    """Reverse of :func:`stack_samples`.

    Useful for turning a mini-batch of samples into a list of samples. These individual
    samples can then be plotted using a dataset's ``plot`` method.

    Taken from `torchgeo`.

    Args:
        sample: a mini-batch of samples

    Returns:
         list of samples

    """
    for key, values in sample.items():
        if isinstance(values, Tensor):
            sample[key] = torch.unbind(values)
    return _dict_list_to_list_dict(sample)