avalanche.training.ClassBalancedBuffer

class avalanche.training.ClassBalancedBuffer(max_size: int, adaptive_size: bool = True, total_num_classes: Optional[int] = None)[source]

Stores samples for replay, equally divided over classes.

There is a separate buffer updated by reservoir sampling for each class. It should be called in the ‘after_training_exp’ phase (see ExperienceBalancedStoragePolicy). The number of classes can be fixed up front or adaptive, based on the ‘adaptive_size’ attribute. When adaptive, the memory is equally divided over all the unique observed classes so far.

__init__(max_size: int, adaptive_size: bool = True, total_num_classes: Optional[int] = None)[source]

Init.

Parameters
  • max_size – The max capacity of the replay memory.

  • adaptive_size – True if mem_size is divided equally over all observed experiences (keys in replay_mem).

  • total_num_classes – If adaptive size is False, the fixed number of classes to divide capacity over.

Methods

__init__(max_size[, adaptive_size, ...])

Init.

get_group_lengths(num_groups)

Compute groups lengths given the number of groups num_groups.

resize(strategy, new_size)

Update the maximum size of the buffers.

update(strategy, **kwargs)

Update self.buffer_groups using the strategy state.

Attributes

buffer

Buffer of samples.

buffer_datasets

Return group buffers as a list of `AvalancheDataset`s.