TransformedDataset
npfl138.TransformedDataset
Bases: Dataset
A dataset capable of applying transformations to its items and batches.
Source code in npfl138/transformed_dataset.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
__init__
__init__(dataset: Dataset) -> None
Create a new transformed dataset using the provided dataset.
Parameters:
-
dataset
(Dataset
) –The source dataset implementing
__len__
and__getitem__
.
Source code in npfl138/transformed_dataset.py
15 16 17 18 19 20 21 |
|
__len__
__len__() -> int
Return the number of items in the dataset.
Source code in npfl138/transformed_dataset.py
23 24 25 |
|
__getitem__
Return the item at the specified index.
Source code in npfl138/transformed_dataset.py
27 28 29 30 31 32 |
|
transform
class-attribute
instance-attribute
transform: Callable | None = None
If given, transform
is called on each item before returning it.
If the dataset item is a tuple, transform
is called with the tuple unpacked.
collate
class-attribute
instance-attribute
collate: Callable | None = None
If given, collate
is called on a list of items before returning them as a batch.
transform_batch
class-attribute
instance-attribute
transform_batch: Callable | None = None
If given, transform_batch
is called on a batch before returning it.
collate_fn
A function for a DataLoader to collate a batch of items using collate
and/or transform_batch
.
This function is used as the collate_fn
parameter of a DataLoader when collate
or transform_batch
is set.
Parameters:
Source code in npfl138/transformed_dataset.py
51 52 53 54 55 56 57 58 59 60 61 62 |
|
dataloader
dataloader(
batch_size=1, *, shuffle=False, num_workers=0, **kwargs
) -> DataLoader
Create a DataLoader for this dataset.
This method is a convenience wrapper around torch.utils.data.DataLoader
setting up the required parameters. All arguments are passed to the DataLoader,
however, when num_workers
is greater than 0, persistent_workers
is set to True.
When collate
or transform_batch
is set, the self.collate_fn
is passed as the
collate_fn
parameter.
Source code in npfl138/transformed_dataset.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|