avalanche.benchmarks.scenarios.NCScenario
- class avalanche.benchmarks.scenarios.NCScenario(train_dataset: TaskAwareClassificationDataset, test_dataset: TaskAwareClassificationDataset, n_experiences: int, task_labels: bool, shuffle: bool = True, seed: int | None = None, fixed_class_order: Sequence[int] | None = None, per_experience_classes: Dict[int, int] | None = None, class_ids_from_zero_from_first_exp: bool = False, class_ids_from_zero_in_each_exp: bool = False, reproducibility_data: Dict[str, Any] | None = 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: TaskAwareClassificationDataset, test_dataset: TaskAwareClassificationDataset, n_experiences: int, task_labels: bool, shuffle: bool = True, seed: int | None = None, fixed_class_order: Sequence[int] | None = None, per_experience_classes: Dict[int, int] | None = None, class_ids_from_zero_from_first_exp: bool = False, class_ids_from_zero_in_each_exp: bool = False, reproducibility_data: Dict[str, Any] | None = None)[source]
Creates a
NCGenericScenarioinstance 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
targetsfield. Classes will be uniformly distributed acrossn_experiencesunless aper_experience_classesargument is specified.The number of classes must be divisible without remainder by the number of experiences. This also applies when the
per_experience_classesargument 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_expparameter.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_datamethod 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
NCGenericScenarioinstance 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_experienceA dictionary mapping each stream (by name) to a list.
n_experiencesThe number of incremental training experiences contained in the train stream.
streamstask_labelsThe task label of each training experience.
classes_orderStores the class order (remapped class IDs).
classes_order_original_idsStores the class order (original class IDs)
class_mappingclass_mapping stores the class mapping so that mapped_class_id = class_mapping[original_class_id].
n_classes_per_expA list that, for each experience (identified by its index/ID), stores the number of classes assigned to that experience.
original_classes_in_expA 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_expIf True the class IDs have been remapped to start from zero.
class_ids_from_zero_in_each_expIf True the class IDs have been remapped to start from zero in each experience
n_classesThe number of classes
train_exps_patterns_assignmentA list containing which training instances are assigned to each experience in the train stream.
test_exps_patterns_assignmentA list containing which test instances are assigned to each experience in the test stream.
stream_definitionsA structure containing the definition of the streams.
original_train_datasetThe original training set.
original_test_datasetThe original test set.
train_streamThe stream used to obtain the training experiences.
test_streamThe stream used to obtain the test experiences.
complete_test_set_onlyIf True, only the complete test set will be returned from experience instances.