avalanche.benchmarks.utils.avalanche_dataset.AvalancheTensorDataset

class avalanche.benchmarks.utils.avalanche_dataset.AvalancheTensorDataset(*dataset_tensors: Sequence, transform: Optional[Callable[[Any], Any]] = None, target_transform: Optional[Callable[[int], int]] = None, transform_groups: Optional[Dict[str, Tuple[Optional[Union[XTransformDef, XComposedTransformDef]], Optional[YTransformDef]]]] = None, initial_transform_group: str = 'train', task_labels: Optional[Union[int, Sequence[int]]] = None, targets: Optional[Union[Sequence[TTargetType], int]] = None, dataset_type: AvalancheDatasetType = AvalancheDatasetType.UNDEFINED, collate_fn: Optional[Callable[[List], Any]] = None, targets_adapter: Optional[Callable[[Any], TTargetType]] = None)[source]

A Dataset that wraps existing ndarrays, Tensors, lists… to provide basic Dataset functionalities. Very similar to TensorDataset from PyTorch, this Dataset also supports transformations, slicing, advanced indexing, the targets field and all the other goodies listed in AvalancheDataset.

__init__(*dataset_tensors: Sequence, transform: Optional[Callable[[Any], Any]] = None, target_transform: Optional[Callable[[int], int]] = None, transform_groups: Optional[Dict[str, Tuple[Optional[Union[XTransformDef, XComposedTransformDef]], Optional[YTransformDef]]]] = None, initial_transform_group: str = 'train', task_labels: Optional[Union[int, Sequence[int]]] = None, targets: Optional[Union[Sequence[TTargetType], int]] = None, dataset_type: AvalancheDatasetType = AvalancheDatasetType.UNDEFINED, collate_fn: Optional[Callable[[List], Any]] = None, targets_adapter: Optional[Callable[[Any], TTargetType]] = None)[source]

Creates a AvalancheTensorDataset instance.

Parameters
  • dataset_tensors – Sequences, Tensors or ndarrays representing the content of the dataset.

  • transform – A function/transform that takes in a single element from the first tensor and returns a transformed version.

  • target_transform – A function/transform that takes a single element of the second tensor and transforms it.

  • transform_groups – A dictionary containing the transform groups. Transform groups are used to quickly switch between training and eval (test) transformations. This becomes useful when in need to test on the training dataset as test transformations usually don’t contain random augmentations. AvalancheDataset natively supports the ‘train’ and ‘eval’ groups by calling the train() and eval() methods. When using custom groups one can use the with_transforms(group_name) method instead. Defaults to None, which means that the current transforms will be used to handle both ‘train’ and ‘eval’ groups (just like in standard torchvision datasets).

  • initial_transform_group – The name of the transform group to be used. Defaults to ‘train’.

  • task_labels – The task labels for each pattern. Must be a sequence of ints, one for each pattern in the dataset. Alternatively can be a single int value, in which case that value will be used as the task label for all the instances. Defaults to None, which means that a default task label “0” will be applied to all patterns.

  • targets – The label of each pattern. Defaults to None, which means that the targets will be retrieved from the dataset. Otherwise, can be 1) a sequence of values containing as many elements as the number of patterns, or 2) the index of the sequence to use as the targets field. When using the default value of None, the targets field will be populated using the second tensor. If dataset is made of only one tensor, then that tensor will be used for the targets field, too.

  • dataset_type – The type of the dataset. Defaults to UNDEFINED. Setting this parameter will automatically set a proper value for collate_fn and targets_adapter. If this parameter is set to a value different from UNDEFINED then collate_fn and targets_adapter must not be set.

  • collate_fn – The function to use when slicing to merge single patterns. In the future this function may become the function used in the data loading process, too.

  • targets_adapter – A function used to convert the values of the targets field. Defaults to None. Note: the adapter will not change the value of the second element returned by __getitem__. The adapter is used to adapt the values of the targets field only.

Methods

__init__(*dataset_tensors[, transform, ...])

Creates a AvalancheTensorDataset instance.

add_transforms([transform, target_transform])

Returns a new dataset with the given transformations added to the existing ones.

add_transforms_group(group_name, transform, ...)

Returns a new dataset with a new transformations group.

add_transforms_to_group(group_name[, ...])

Returns a new dataset with the given transformations added to the existing ones for a certain group.

eval()

Returns a new dataset with the transformations of the 'eval' group loaded.

freeze_group_transforms(group_name)

Returns a new dataset where the transformations for a specific group are frozen.

freeze_transforms()

Returns a new dataset where the current transformations are frozen.

get_transforms([transforms_group])

Returns the transformations given a group.

replace_transforms(transform, target_transform)

Returns a new dataset with the existing transformations replaced with the given ones.

train()

Returns a new dataset with the transformations of the 'train' group loaded.

with_transforms(group_name)

Returns a new dataset with the transformations of a different group loaded.

Attributes