DatasetWrapper

class hybrid_learning.datasets.activations_handle.DatasetWrapper(dataset, **data_args)[source]

Bases: BaseDataset

Wrap a dataset or subset to add caches or transforms. Wrapping a dataset with a DatasetWrapper has the same effect as the in-place version

dataset.transforms_cache = new_cache + cache
dataset.transforms = transforms + new_transforms

but without changing the wrapped dataset. In case the data is a torch.utils.data.Subset instance, care is taken to correctly retrieve the descriptor of the subsetted data (without mixing up indices), see descriptor().

Note

dataset is read-only, and the dataset should not be changed. Create a new wrapper if this is necessary.

Public Data Attributes:

dataset

The wrapped dataset.

Inherited from : py: class:BaseDataset

settings

Settings of the instance.

Public Methods:

getitem(idx)

Wrap the __getitem__ of the wrapped dataset.

descriptor(i)

Wrap descriptor method of wrapped dataset.

Inherited from : py: class:BaseDataset

getitem(idx)

Wrap the __getitem__ of the wrapped dataset.

descriptor(i)

Wrap descriptor method of wrapped dataset.

Special Methods:

__init__(dataset, **data_args)

Init.

__len__()

Length determined by the length of the wrapped dataset.

Inherited from : py: class:BaseDataset

__init__(dataset, **data_args)

Init.

__len__()

Length determined by the length of the wrapped dataset.

__getitem__(idx)

Get item from idx in dataset with transformations applied.

__repr__()

Nice printing function.

Inherited from : py: class:Dataset

__getitem__(idx)

Get item from idx in dataset with transformations applied.

__add__(other)


__init__(dataset, **data_args)[source]

Init.

Parameters

dataset (Union[torch.utils.data.Subset, BaseDataset, Sequence]) – Dataset to wrap; must be a sequence of tuples of (image, ground_truth) with both image and ground-truth of type torch.Tensor;

__len__()[source]

Length determined by the length of the wrapped dataset. See dataset.

Return type

int

descriptor(i)[source]

Wrap descriptor method of wrapped dataset. It is assumed that either dataset or self.dataset.dataset provide a function descriptor(i: int). This is e.g. the case for a hybrid_learning.datasets.base.BaseDataset or a torch.utils.data.Subset instance. In case of a subset instance, care is taken to heed the index shuffling.

Parameters

i (int) –

Return type

str

getitem(idx)[source]

Wrap the __getitem__ of the wrapped dataset.

Parameters

idx (int) –

Return type

Tuple[Union[Tensor, Image], Union[Tensor, Image, Dict[Tensor, Image]]]

__parameters__ = ()
property dataset: Union[torch.utils.data.Subset, BaseDataset, Sequence]

The wrapped dataset.