Skip to content

afnio.utils.data.dataset

afnio.utils.data.dataset.Dataset

Bases: Generic[T_co]

An abstract class representing a Dataset.

All datasets that represent a map from keys to data samples should subclass it. All subclasses should overwrite __getitem__(), supporting fetching a data sample for a given key and __len__(), which is expected to return the size of the dataset by the default options of DataLoader. Subclasses could also optionally implement __getitems__(), for speedup batched samples loading. This method accepts list of indices of samples of batch and returns list of samples.

Source code in afnio/utils/data/dataset.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Dataset(Generic[T_co]):
    """An abstract class representing a [`Dataset`][.].

    All datasets that represent a map from keys to data samples should subclass
    it. All subclasses should overwrite `__getitem__()`, supporting fetching a
    data sample for a given key and `__len__()`, which is expected to return
    the size of the dataset by the default options of
    [`DataLoader`][afnio.utils.data.dataloader.DataLoader]. Subclasses could also
    optionally implement `__getitems__()`, for speedup batched samples loading.
    This method accepts list of indices of samples of batch and returns list of samples.
    """

    def __getitem__(self, index) -> T_co:
        raise NotImplementedError("Subclasses of Dataset should implement __getitem__.")

    def __len__(self):
        raise NotImplementedError("Subclasses of Dataset should implement __len__.")