Centroids Matching: an efficient Continual Learning approach operating in the embedding space

Jary Pomponi, Simone Scardapane, Aurelio Uncini

Abstract

Catastrophic forgetting (CF) occurs when a neural network loses the information previously learned while training on a set of samples from a different distribution, i.e., a new task. Existing approaches have achieved remarkable results in mitigating CF, especially in a scenario called task incremental learning. However, this scenario is not realistic, and limited work has been done to achieve good results on more realistic scenarios. In this paper, we propose a novel regularization method called Centroids Matching, that, inspired by meta-learning approaches, fights CF by operating in the feature space produced by the neural network, achieving good results while requiring a small memory footprint. Specifically, the approach classifies the samples directly using the feature vectors produced by the neural network, by matching those vectors with the centroids representing the classes from the current task, or all the tasks up to that point. Centroids Matching is faster than competing baselines, and it can be exploited to efficiently mitigate CF, by preserving the distances between the embedding space produced by the model when past tasks were over, and the one currently produced, leading to a method that achieves high accuracy on all the tasks, without using an external memory when operating on easy scenarios, or using a small one for more realistic ones. Extensive experiments demonstrate that Centroids Matching achieves accuracy gains on multiple datasets and scenarios.

Introduction

The "holy grail" of AI is a model that can learn continuously from a stream of data, just like a human. However, standard neural networks suffer from Catastrophic Forgetting (CF): when they learn a new task (e.g., recognizing birds), they often completely overwrite the weights used for a previous task (e.g., recognizing cars).

Researchers typically evaluate solutions in two primary scenarios:

  1. Task Incremental Learning (TIL): The model is provided with the task ID during testing, allowing it to use task-specific parameters.
  2. Class Incremental Learning (CIL): The model must distinguish between all classes it has ever seen without being told the task ID. This is significantly more challenging and realistic.

Existing solutions often require saving a large "memory" of past images (rehearsal) or are computationally expensive. Centroids Matching (CM) seeks to be both memory-efficient and fast while performing well in both scenarios.

Methodology

Centroids Matching shifts the focus from raw classification (logits) to the embedding space (the internal feature representations).

Centroid-Based Classification

Inspired by Prototypical Networks, CM replaces the standard final linear layer with a distance-based approach. It calculates a "centroid" (the average feature vector) for every class using a small "support set" of images. To classify a new image, the model calculates its feature vector and finds the nearest centroid in the embedding space.

Distance-Based Regularization (TIL)

To prevent forgetting in the TIL scenario, CM employs a zero-memory regularization trick. When learning a new task, it forces the current model to produce feature vectors that are geometrically similar to what a frozen clone of the previous model would have produced for the current data. This maintains the stability of the feature extractor without needing to store old data.

Space Merging (CIL)

In the CIL scenario, the model uses a small external memory of past samples. It employs a Projection Function—a small neural network that scales and translates vectors—to map task-specific embedding spaces into one unified global space where all classes can be compared simultaneously.

Comparison of Task Incremental and Class Incremental scenarios in the Centroids Matching framework.

Experimental Setup

The approach was validated on three standard computer vision benchmarks, split into incremental tasks:

  • CIFAR-10: 5 tasks, 2 classes each.
  • CIFAR-100: 10 tasks, 10 classes each.
  • TinyImageNet: 10 tasks, 20 classes each.

Key Results and Discussion

Centroids Matching consistently outperformed or matched top-tier baselines like Experience Replay (ER) and Elastic Weight Consolidation (EWC):

  • Accuracy: On CIFAR-10 (TIL), CM achieved 92.72% accuracy, outperforming ER (90.56%) and GEM (90.15%). In the difficult CIL scenario on CIFAR-100, it reached 27.91%, significantly higher than EWC (6.13%) and SS-IL (24.13%).
  • Forgetting: CM showed very low "Backward Transfer" (BWT) values, indicating minimal accuracy loss on old tasks as new ones were learned.
  • Efficiency: Training time for CM grows much more slowly than rehearsal-based methods. For the 5th task of CIFAR-10, CM took ~48 seconds per epoch, while ER took ~113 seconds.

Insights

The core innovation of CM is prioritizing Geometry over Weights. By preserving the relative distances between features in the embedding space, the model avoids the interference that occurs when a single classification layer is forced to learn everything at once. Furthermore, the use of Voronoi diagrams for visualization confirms that new classes are "slotted in" to empty areas of the feature space without disrupting the clusters of old classes.

Conclusion

While highly efficient, Centroids Matching faces challenges regarding Support Set Sensitivity, as performance depends on the quality of the images used to calculate centroids. Additionally, while TIL requires zero data memory, the CIL scenario still benefits from a small external buffer. Future work will explore scaling this approach to larger datasets like ImageNet and different modalities such as Natural Language Processing.

Summary updated

BibTeX
@article{pomponi2022centroids,
  author = {Jary Pomponi and Simone Scardapane and Aurelio Uncini},
  title = {{Centroids Matching: an efficient Continual Learning approach operating in the embedding space}},
  journal = {Accepted by TMLR},
  year = {2022},
  url = {https://openreview.net/forum?id=7gzQltQSwr},
}
Figure