mirror of
https://github.com/wassname/pytorch-ts.git
synced 2026-07-08 20:00:29 +08:00
34 lines
918 B
Python
34 lines
918 B
Python
from typing import Iterator, List
|
|
|
|
from pts.dataset import DataEntry, Dataset
|
|
from .transform import Chain, Transformation
|
|
|
|
|
|
class TransformedDataset(Dataset):
|
|
"""
|
|
A dataset that corresponds to applying a list of transformations to each
|
|
element in the base_dataset.
|
|
This only supports SimpleTransformations, which do the same thing at
|
|
prediction and training time.
|
|
|
|
|
|
Parameters
|
|
----------
|
|
base_dataset
|
|
Dataset to transform
|
|
transformations
|
|
List of transformations to apply
|
|
"""
|
|
|
|
def __init__(
|
|
self, base_dataset: Dataset, transformations: List[Transformation]
|
|
) -> None:
|
|
self.base_dataset = base_dataset
|
|
self.transformations = Chain(transformations)
|
|
|
|
def __iter__(self) -> Iterator[DataEntry]:
|
|
yield from self.transformations(self.base_dataset, is_train=True)
|
|
|
|
def __len__(self):
|
|
return sum(1 for _ in self)
|