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 versiondataset.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), seedescriptor()
.Note
dataset
is read-only, and the dataset should not be changed. Create a new wrapper if this is necessary.Public Data Attributes:
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 typetorch.Tensor
;
- descriptor(i)[source]
Wrap descriptor method of wrapped dataset. It is assumed that either
dataset
orself.dataset.dataset
provide a functiondescriptor(i: int)
. This is e.g. the case for ahybrid_learning.datasets.base.BaseDataset
or atorch.utils.data.Subset
instance. In case of a subset instance, care is taken to heed the index shuffling.
- __parameters__ = ()
-
property dataset: Union[
torch.utils.data.Subset
, BaseDataset, Sequence] The wrapped dataset.