- class flamo.optimize.dataset.Dataset(input: Tensor = tensor([[1.5410]]), target: Tensor = tensor([[-0.2934]]), expand: int = 1, device: str = 'cpu')
Base Dataset class. Inherits from
torch.utils.data.Dataset.In simple gradient descent optimization of differentiable DSP, both the input and target are represented by individual tensors. Therefore, the dataset consists of a single input tensor and a single target tensor. To accommodate larger datasets, the input and target tensors can be expanded to the desired dataset length using the
expandattribute. This enables performing multiple optimization steps within a single epoch and allows for batch sizes greater than 1.- Arguments / Attributes:
input (torch.Tensor, optional): The input data tensor. Default: torch.randn(100, 100).
target (torch.Tensor, optional): The target data tensor. Default: torch.randn(100, 100).
expand (int): The first shape dimention of the input and target tensor after expansion. Default: 1. This coincides with the length on the dataset.
device (str, optional): The device to store the tensors on. Default: ‘cpu’.
- class flamo.optimize.dataset.DatasetColorless(input_shape: tuple, target_shape: tuple, expand: int = 1000, device: str = 'cpu')
A dataset class for colorless optimization.
The input tensor is an impulse of length
input_shape. The target is an instance of torch.ones with the shapetarget_shape, corresponding to a flat magnitude spectrum.- Arguments / Attributes:
input_shape (tuple): The shape of the input data.
target_shape (tuple): The shape of the target data.
expand (int, optional): The number of times to expand the dataset. Defaults to 1000.
device (str, optional): The device to use for computation. Defaults to ‘cpu’.
For details on the colorless optimization, see https://arxiv.org/abs/2402.11216v2.
- flamo.optimize.dataset.get_dataloader(dataset: Dataset, batch_size: int = 2000, shuffle: bool = True)
Create a torch dataloader
torch.utils.data.DataLoaderfrom the given dataset.- Arguments:
dataset (torch.utils.data.Dataset): The dataset to create the dataloader from.
batch_size (int, optional): The number of samples per batch to load. Default: 2000.
shuffle (bool, optional): Whether to shuffle the dataset before each epoch. Default: True.
- Returns:
torch.utils.data.DataLoader: The dataloader.
- flamo.optimize.dataset.split_dataset(dataset: Dataset, split: float)
Splits the given dataset into a training set and a validation set based on the specified split ratio.
- Arguments:
dataset (torch.utils.data.Dataset): The dataset to be split.
split (float): The ratio of the training set size to the total dataset size.
- Returns:
tuple: A tuple containing the training set and the validation set.
- flamo.optimize.dataset.load_dataset(dataset: Dataset, batch_size: int = 2000, split: float = 0.8, shuffle: bool = True)
Load and split a dataset into training and validation sets.
- Arguments:
dataset (torch.utils.data.Dataset): The dataset to be loaded.
batch_size (int, optional): The batch size for the data loaders. Defaults to 2000.
split (float, optional): The ratio to split the dataset into training and validation sets. Defaults to 0.8.
shuffle (bool, optional): Whether to shuffle the data. Defaults to True.
- Returns:
tuple: A tuple containing the training and validation data loaders.