avalanche.benchmarks.scenarios.NCScenario

class avalanche.benchmarks.scenarios.NCScenario(train_dataset: AvalancheDataset, test_dataset: AvalancheDataset, n_experiences: int, task_labels: bool, shuffle: bool = True, seed: Optional[int] = None, fixed_class_order: Optional[Sequence[int]] = None, per_experience_classes: Optional[Dict[int, int]] = None, class_ids_from_zero_from_first_exp: bool = False, class_ids_from_zero_in_each_exp: bool = False, reproducibility_data: Optional[Dict[str, Any]] = None)[source]

This class defines a “New Classes” scenario. Once created, an instance of this class can be iterated in order to obtain the experience sequence under the form of instances of NCExperience.

This class can be used directly. However, we recommend using facilities like avalanche.benchmarks.generators.nc_benchmark().

__init__(train_dataset: AvalancheDataset, test_dataset: AvalancheDataset, n_experiences: int, task_labels: bool, shuffle: bool = True, seed: Optional[int] = None, fixed_class_order: Optional[Sequence[int]] = None, per_experience_classes: Optional[Dict[int, int]] = None, class_ids_from_zero_from_first_exp: bool = False, class_ids_from_zero_in_each_exp: bool = False, reproducibility_data: Optional[Dict[str, Any]] = None)[source]

Creates a NCGenericScenario instance given the training and test Datasets and the number of experiences.

By default, the number of classes will be automatically detected by looking at the training Dataset targets field. Classes will be uniformly distributed across n_experiences unless a per_experience_classes argument is specified.

The number of classes must be divisible without remainder by the number of experiences. This also applies when the per_experience_classes argument is not None.

Parameters
  • train_dataset – The training dataset. The dataset must be a subclass of AvalancheDataset. For instance, one can use the datasets from the torchvision package like that: train_dataset=AvalancheDataset(torchvision_dataset).

  • test_dataset – The test dataset. The dataset must be a subclass of AvalancheDataset. For instance, one can use the datasets from the torchvision package like that: test_dataset=AvalancheDataset(torchvision_dataset).

  • n_experiences – The number of experiences.

  • task_labels – If True, each experience will have an ascending task label. If False, the task label will be 0 for all the experiences.

  • shuffle – If True, the class order will be shuffled. Defaults to True.

  • seed – If shuffle is True and seed is not None, the class order will be shuffled according to the seed. When None, the current PyTorch random number generator state will be used. Defaults to None.

  • fixed_class_order – If not None, the class order to use (overrides the shuffle argument). Very useful for enhancing reproducibility. Defaults to None.

  • per_experience_classes – Is not None, a dictionary whose keys are (0-indexed) experience IDs and their values are the number of classes to include in the respective experiences. The dictionary doesn’t have to contain a key for each experience! All the remaining experiences will contain an equal amount of the remaining classes. The remaining number of classes must be divisible without remainder by the remaining number of experiences. For instance, if you want to include 50 classes in the first experience while equally distributing remaining classes across remaining experiences, just pass the “{0: 50}” dictionary as the per_experience_classes parameter. Defaults to None.

  • class_ids_from_zero_from_first_exp – If True, original class IDs will be remapped so that they will appear as having an ascending order. For instance, if the resulting class order after shuffling (or defined by fixed_class_order) is [23, 34, 11, 7, 6, …] and class_ids_from_zero_from_first_exp is True, then all the patterns belonging to class 23 will appear as belonging to class “0”, class “34” will be mapped to “1”, class “11” to “2” and so on. This is very useful when drawing confusion matrices and when dealing with algorithms with dynamic head expansion. Defaults to False. Mutually exclusive with the class_ids_from_zero_in_each_exp parameter.

  • class_ids_from_zero_in_each_exp – If True, original class IDs will be mapped to range [0, n_classes_in_exp) for each experience. Defaults to False. Mutually exclusive with the class_ids_from_zero_from_first_exp parameter.

  • reproducibility_data – If not None, overrides all the other scenario definition options. This is usually a dictionary containing data used to reproduce a specific experiment. One can use the get_reproducibility_data method to get (and even distribute) the experiment setup so that it can be loaded by passing it as this parameter. In this way one can be sure that the same specific experimental setup is being used (for reproducibility purposes). Beware that, in order to reproduce an experiment, the same train and test datasets must be used. Defaults to None.

Methods

__init__(train_dataset, test_dataset, ...[, ...])

Creates a NCGenericScenario instance given the training and test Datasets and the number of experiences.

classes_in_exp_range(exp_start[, exp_end])

Gets a list of classes contained in the given experiences.

get_classes_timeline(current_experience[, ...])

Returns the classes timeline given the ID of a experience.

get_reproducibility_data()

Gets the data needed to reproduce this experiment.

Attributes

classes_in_experience

A dictionary mapping each stream (by name) to a list.

n_experiences

The number of incremental training experiences contained in the train stream.

streams

task_labels

The task label of each training experience.

classes_order

Stores the class order (remapped class IDs).

classes_order_original_ids

Stores the class order (original class IDs)

class_mapping

class_mapping stores the class mapping so that mapped_class_id = class_mapping[original_class_id].

n_classes_per_exp

A list that, for each experience (identified by its index/ID), stores the number of classes assigned to that experience.

original_classes_in_exp

A list that, for each experience (identified by its index/ID), stores a set of the original IDs of classes assigned to that experience.

class_ids_from_zero_from_first_exp

If True the class IDs have been remapped to start from zero.

class_ids_from_zero_in_each_exp

If True the class IDs have been remapped to start from zero in each experience

n_classes

The number of classes

train_exps_patterns_assignment

A list containing which training instances are assigned to each experience in the train stream.

test_exps_patterns_assignment

A list containing which test instances are assigned to each experience in the test stream.