Utils#
- utils.create_if_not_exists(path)[source]#
Creates the specified folder if it does not exist.
- Parameters:
path (str) – the complete path of the folder to be created
- utils.infer_args_from_signature(signature, excluded_signature=None)[source]#
Load the arguments of a function from its signature.
- utils.register_dynamic_module_fn(name, register)[source]#
Register a dynamic module in the specified dictionary.
Submodules#
Args#
Buffer#
- class utils.buffer.BaseSampleSelection(buffer_size, device)[source]#
Bases:
object
Base class for sample selection strategies.
- class utils.buffer.Buffer(buffer_size, device='cpu')[source]#
Bases:
object
The memory buffer of rehearsal method.
- add_data(examples, labels=None, logits=None, task_labels=None, true_labels=None, sample_selection_scores=None)[source]#
Adds the data to the memory buffer according to the reservoir strategy.
- Parameters:
examples – tensor containing the images
labels – tensor containing the labels
logits – tensor containing the outputs of the network
task_labels – tensor containing the task labels
true_labels – if setting is noisy, the true labels associated with the examples. Used only for logging.
sample_selection_scores – tensor containing the scores used for the sample selection strategy. NOTE: this is only used if the sample selection strategy defines the update method.
Note
Only the examples are required. The other tensors are initialized only if they are provided.
- examples: Tensor#
- get_data(size, transform=None, device=None)[source]#
Random samples a batch of size items.
- Parameters:
- Returns:
a tuple containing the requested items. If return_index is True, the tuple contains the indexes as first element.
- Return type:
Sequence[Tensor]
- init_tensors(examples, labels, logits, task_labels, true_labels)[source]#
Initializes just the required tensors.
- Parameters:
examples (Tensor) – tensor containing the images
labels (Tensor) – tensor containing the labels
logits (Tensor) – tensor containing the outputs of the network
task_labels (Tensor) – tensor containing the task labels
true_labels (Tensor) – tensor containing the true labels (used only for logging)
- labels: Tensor#
- logits: Tensor#
- serialize(out_device='cpu')[source]#
Serialize the buffer.
- Returns:
A dictionary containing the buffer attributes.
- task_labels: Tensor#
- to(device)[source]#
Move the buffer and its attributes to the specified device.
- Parameters:
device – The device to move the buffer and its attributes to.
- Returns:
The buffer instance with the updated device and attributes.
- true_labels: Tensor#
- property used_attributes#
Returns a list of attributes that are currently being used by the object.
- class utils.buffer.ReservoirSampling(buffer_size, device)[source]#
Bases:
BaseSampleSelection
Checkpoints#
- utils.checkpoints.mammoth_load_checkpoint(args, model)[source]#
Loads the keys from the given checkpoint. - Handles DataParallel and DistributedDataParallel checkpoints. - Handles checkpoints from previous versions of the code. - Handles head initialization for LUCIR.
Configuration#
This module contains utility functions for configuration settings.
Evaluation#
- utils.evaluate.evaluate(model, dataset, last_only=False)[source]#
Evaluates the single-class top-1 accuracy of the model for each past task.
The accuracy is evaluated for all the tasks up to the current one, only for the total number of classes seen so far.
- Parameters:
model (ContinualModel) – the model to be evaluated
dataset (ContinualDataset) – the continual dataset at hand
last_only – if True, only the last task is evaluated. Defaults to False.
- Returns:
a tuple of lists, containing the class-il and task-il accuracy for each task.
- Return type:
- utils.evaluate.mask_classes(outputs, dataset, k)[source]#
Given the output tensor, the dataset at hand and the current task, masks the former by setting the responses for the other tasks at -inf. It is used to obtain the results for the task-il setting.
- Parameters:
outputs (Tensor) – the output tensor
dataset (ContinualDataset) – the continual dataset
k (int) – the task index
Training#
- utils.training.train(model, dataset, args=None)[source]#
The training process, including evaluations and loggers.
- Parameters:
model (ContinualModel) – the module to be trained
dataset (ContinualDataset) – the continual dataset at hand
args (Namespace | None) – the arguments of the current execution. If None, it will be loaded from the environment variable ‘MAMMOTH_ARGS’.