Skip to content

extend_dataset

ExtendDataset

Bases: Dataset

ExtendDataset either extends or contracts the length of provided Dataset.

Parameters:

Name Type Description Default
dataset Dataset

The Original dataset(s) which need expansion or contraction.

required
spoof_length int

Length to which original dataset must be expanded or contracted to. (New desired length)

required
Source code in fastestimator\fastestimator\dataset\extend_dataset.py
@traceable()
class ExtendDataset(Dataset):
    """ExtendDataset either extends or contracts the length of provided Dataset.

    Args:
        dataset: The Original dataset(s) which need expansion or contraction.
        spoof_length: Length to which original dataset must be expanded or contracted to. (New desired length)
    """
    def __init__(self, dataset: Dataset, spoof_length: int) -> None:
        self.dataset = dataset
        self.spoof_length = spoof_length
        self._check_input()
        if hasattr(dataset, "fe_reset_ds"):
            self.fe_reset_ds = dataset.fe_reset_ds
        if hasattr(dataset, "fe_batch_indices"):
            self.fe_batch_indices = dataset.fe_batch_indices
        if hasattr(dataset, "fe_batch"):
            self.fe_batch = dataset.fe_batch

    def __len__(self):
        return len(self.dataset)

    def _check_input(self) -> None:
        """Verify that the given input values are valid.
        Raises:
            AssertionError: If any of the parameters are found to by unacceptable for a variety of reasons.
        """
        assert isinstance(self.spoof_length, int), "Only accept positive integer type as spoof_length"
        assert self.spoof_length > 0, "Invalid spoof_length. Expand Length cannot be less than or equal to 0"
        assert not isinstance(self.dataset, ExtendDataset), "Input Dataset cannot be an ExtendDataset object"

    def __getitem__(self, index):
        return self.dataset[index]