Giter VIP home page Giter VIP logo

cil_survey's Introduction

Class-Incremental Learning: A Survey

The code repository for "Class-Incremental Learning: A Survey" in PyTorch. If you use any content of this repo for your work, please cite the following bib entry:

@article{zhou2024class,
    author = {Zhou, Da-Wei and Wang, Qi-Wei and Qi, Zhi-Hong and Ye, Han-Jia and Zhan, De-Chuan and Liu, Ziwei},
    title = {Class-Incremental Learning: A Survey},
    journal={IEEE Transactions on Pattern Analysis and Machine Intelligence},
    year = {2024}
 }

Feel free to create new issues or drop me an email if you find any interesting paper missing in our survey, and we shall include them in the next version.

Updates

[07/2024] Accepted to TPAMI.

[02/2023] arXiv paper has been released.

[02/2023] The code has been released.

Introduction

Deep models, e.g., CNNs and Vision Transformers, have achieved impressive achievements in many vision tasks in the closed world. However, novel classes emerge from time to time in our ever-changing world, requiring a learning system to acquire new knowledge continually. For example, a robot needs to understand new instructions, and an opinion monitoring system should analyze emerging topics every day. Class-Incremental Learning (CIL) enables the learner to incorporate the knowledge of new classes incrementally and build a universal classifier among all seen classes. Correspondingly, when directly training the model with new class instances, a fatal problem occurs --- the model tends to catastrophically forget the characteristics of former ones, and its performance drastically degrades. There have been numerous efforts to tackle catastrophic forgetting in the machine learning community. In this paper, we survey comprehensively recent advances in deep class-incremental learning and summarize these methods from three aspects, i.e., data-centric, model-centric, and algorithm-centric. We also provide a rigorous and unified evaluation of 16 methods in benchmark image classification tasks to find out the characteristics of different algorithms empirically. Furthermore, we notice that the current comparison protocol ignores the influence of memory budget in model storage, which may result in unfair comparison and biased results. Hence, we advocate fair comparison by aligning the memory budget in evaluation, as well as several memory-agnostic performance measures.

Requirements

Environment

Here are the requirements for running the code:

  1. torch 1.81
  2. torchvision 0.6.0
  3. tqdm
  4. numpy
  5. scipy
  6. quadprog
  7. POT

Dataset

We use CIFAR100 and ImageNet100/1000 for our experiments. CIFAR100 will be automatically downloaded when running the code.

Here is the file list of ImageNet100.

Pre-Trained Models

As discussed in the main paper, we aim for a fair comparison among different methods and align the performance at the first stage. Please refer to the instructions to download the pre-trained models in the following section.

Code Structures

  • checkpoints: We supply the same pre-trained checkpoints for most methods for a fair comparison. Please download the checkpoint from Google Drive or Onedrive and put these checkpoints in this folder.
  • convs: The network structures adopted in the implementation.
  • exps: The default config files for compared methods. It should be noted that these config files will be overwritten by the parameters (e.g., function setup_parser in main.py) passed via the command line.
  • scripts: The scripts for running the code in our evaluations.
  • models: The implementation of different CIL methods.
  • utils: Useful functions for dataloader and incremental actions.

Supported Methods

  • FineTune: Baseline method which simply updates parameters on new tasks and suffers from catastrophic forgetting.
  • EWC: Overcoming catastrophic forgetting in neural networks. PNAS2017 [paper]
  • LwF: Learning without Forgetting. ECCV2016 [paper]
  • Replay: Baseline method with exemplars.
  • GEM: Gradient Episodic Memory for Continual Learning. NIPS2017 [paper]
  • iCaRL: Incremental Classifier and Representation Learning. CVPR2017 [paper]
  • BiC: Large Scale Incremental Learning. CVPR2019 [paper]
  • WA: Maintaining Discrimination and Fairness in Class Incremental Learning. CVPR2020 [paper]
  • PODNet: PODNet: Pooled Outputs Distillation for Small-Tasks Incremental Learning. ECCV2020 [paper]
  • DER: DER: Dynamically Expandable Representation for Class Incremental Learning. CVPR2021 [paper]
  • RMM: RMM: Reinforced Memory Management for Class-Incremental Learning. NeurIPS2021 [paper]
  • Coil: Co-Transport for Class-Incremental Learning. ACM MM2021 [paper]
  • FOSTER: Feature Boosting and Compression for Class-incremental Learning. ECCV 2022 [paper]
  • MEMO: A Model or 603 Exemplars: Towards Memory-Efficient Class-Incremental Learning. ICLR 2023 [paper]

Towards a Fair Comparison of Class-Incremental Learning

In the main paper, we conduct three types of empirical evaluations to find out the characteristics of different methods. They are listed as:

  • Benchmark comparison: compares the performance of different methods with the same number of exemplars, e.g., 2000 for CIFAR100.
  • Memory-aligned comparison: compares the performance of different methods with the same memory budget to DER. For those methods that consume less budget than DER, we align the cost by saving extra exemplars. For example, a ResNet32 model costs 463,504 parameters (float), while a CIFAR image requires 3 × 32 × 32 integer numbers (int). Hence, the budget for saving a backbone is equal to saving 463,504 floats ×4 bytes/float ÷(3 × 32 × 32) bytes/image ≈ 603 exemplars for CIFAR. Specifically, the memory cost of different methods in traditional benchmark protocol is shown in the left figure, while memory-aligned comparison advocates comparison in the right figure.
  • Memory-agnostic comparison: extends the memory-aligned comparison to the memory-agnostic performance measures, e.g., AUC-A and AUC-L. We set several memory budgets and align the cost of each method to them, drawing the performance-memory curve. The memory-agnostic comparison is not based on any assigned budget, which better measures the extendability of class-incremental learning models.

Method CIFAR100 Base0 Inc10 ImageNet100 Base50 Inc5
AUC-A AUC-L AUC-A AUC-L
GEM 4.31 1.70 - -
Replay 10.49 8.02 553.6 470.1
iCaRL 10.81 8.64 607.1 527.5
PODNet 9.42 6.80 701.8 624.9
Coil 10.60 7.82 601.9 486.5
WA 10.80 8.92 666.0 581.7
BiC 10.73 8.30 592.7 474.2
FOSTER 11.12 9.03 638.7 566.3
DER 10.74 8.95 699.0 639.1
MEMO 10.85 9.03 713.0 654.6

Visualizations

We provide the visualizations of the confusion matrix and weight norm of classifiers in class-incremental learning. These visualizations are drawn with the logs after running the code.

Running scripts

There are three types of experiments in our survey, i.e., benchmark, memory-aligned (fair), and memory-agnostic (auc) in the scripts folder). We give all the scripts for running the experiments in this paper. For example, if you are interested in the benchmark comparison, please run the following command:

bash ./scripts/benchmark/cifar_b0_5_finetune.sh

Similarly, you can run the other scripts in the same way.

Calculating the number of exemplars

It must be noted that the memory-aligned and memory-agnostic comparison protocol requires calculating the number of exemplars for each method. Please refer to compute_exemplar.py for more details. The following is an example of calculating the number of exemplars for the fair and auc protocol.

Fair

bash run-fair.sh

AUC

python compute_exemplar.py -p auc

Acknowledgment

This repo is modified from PyCIL.

Correspondence

This repo is developed and maintained by Qi-Wei Wang and Zhi-Hong Qi. If you have any questions, please feel free to contact us by opening new issues or email:

visitors

cil_survey's People

Contributors

vita-qzh avatar wangkiw avatar zhoudw-zdw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

cil_survey's Issues

About select methods

Hello, I think your work is very meaningful!
I would like to ask you about the 16 selected methods mentioned in your paper, including the methods using transformer structure, such as dytox, l2p and dualprompt, which have not been included in this project. How can I reproduce the comparison of these parts? Is there any plan to release it later?

Looking forward to your reply, best wishes!

Accuracy logging information

Hi, I found that the 'increment' parameter of the 'accuracy' method in 'toolkit.py' is always 10 by default. Shall the actual increment number be passed to it when calling the method in the base model?

Fake target in Loss function problems.

I got a problems when using your code in different datasets. The loss reduced to 0 but the training accuracy did not increase. This is because of only using partial data /tensor in the last layers (fake target implementation). That leads to loss equals while the prediction results is not correct. So this affect methods using custom losses (finetune, lwf, memo, ...)

For example, I set number of classes = 2, this is the task 3 (training on classes 4-5)

from torch import Tensor
import torch

from torch.nn import functional as F
tensor = Tensor(
[
    [-3.6737,   3.6739,   7.9670,  -6.8142,   7.5660,  -7.4853],
    [-3.8698,   3.8700,   8.3494,  -7.1354,   7.9662,  -7.8834],
    [3.0694,  -3.0693,  -6.3453,   4.8575, -14.1109,  14.8372],
    [3.0781,  -3.0780,  -6.3650,   4.8734, -14.1494,  14.8778],
    [-3.7971,   3.7972,   8.2072,  -7.0160,   7.8165,  -7.7347],
    [-3.7736,   3.7738,   8.1614,  -6.9775,   7.7684,  -7.6869],
    [-3.7105,   3.7107,   8.0386,  -6.8743,   7.6404,  -7.5594],
    [-3.7717,   3.7719,   8.1577,  -6.9744,   7.7645,  -7.6830],
    [-3.8698,   3.8700,   8.3495,  -7.1355,   7.9662,  -7.8834],
    [3.1876,  -3.1874,  -6.6086,   5.0743, -14.6059,  15.3588],
    [-3.7871,   3.7873,   8.1883,  -7.0001,   7.7980,  -7.7159],
    [3.1329,  -3.1327,  -6.4858,   4.9743, -14.3710,  15.1113],
    [3.1295,  -3.1293,  -6.4794,   4.9677, -14.3636,  15.1034],
    [-3.6428,   3.6429,   7.9025,  -6.7601,   7.4887,  -7.4108],
    [3.0746,  -3.0745,  -6.3574,   4.8670, -14.1357,  14.8634],
    [3.2236,  -3.2235,  -6.6936,   5.1387, -14.7841,  15.5461],
    [3.1713,  -3.1712,  -6.5750,   5.0436, -14.5523,  15.3020],
    [-3.7287,   3.7289,   8.0736,  -6.9037,   7.6759,  -7.5950],
    [3.0622,  -3.0621,  -6.3294,   4.8443, -14.0822,  14.8070],
    [3.2201,  -3.2200,  -6.6833,   5.1333, -14.7547,  15.5154],
    [-3.4313,   3.4315,   7.4917,  -6.4150,   7.0624,  -6.9858],
    [-3.6644,   3.6645,   7.9488,  -6.7989,   7.5468,  -7.4662]
]
)
target = Tensor(
    [4, 4, 5, 5, 4, 4, 4, 4, 4, 5, 4, 5, 5, 4, 5, 5, 5, 4, 5, 5, 4, 4]
)
print(target)
prediction = torch.max(tensor, dim=1)
print(prediction)
target = target.to(dtype=torch.int64)
fake_target = target - 4
print(F.cross_entropy(tensor[:, 4:], fake_target))

Labels for task>0

Hi.

Thank you for this great Library for Continual Learning.

I wanted to ask regarding the label mapping when we are at the task 2 of class incremental training. Let's say I am training a simple finetuning model.

I am training on CIFAR100 on an increment of 10 classes in each task. The first training will have labels [0,1,2,3,4,5,6,7,8,9]. For the second task, the labels are [10,11,12,13,14,15,16,17,18,19]. Do you map these to [0,1,2,3,4,5,6,7,8,9] or use some other loss function instead of cross-entropy? If you map it, can you please point out the code piece. And how do you handle this at inference time?

Thanks in Advance.

Bugs in Der and Foster?

Thanks for your sharing!
I'd be grateful if you could help me with the bug when reproducing the der.json & foster.json on VTab.

Details belike:
File "LAMDA-PILOT-main/models/base.py", line 260, in _construct_exemplar
i = np.argmin(np.sqrt(np.sum((class_mean - mu_p) ** 2, axis=1)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "envs/pilot/lib/python3.11/site-packages/numpy/core/fromnumeric.py", line 1325, in argmin
return _wrapfunc(a, 'argmin', axis=axis, out=out, **kwds)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "pilot/lib/python3.11/site-packages/numpy/core/fromnumeric.py", line 59, in _wrapfunc
return bound(*args, **kwds)
^^^^^^^^^^^^^^^^^^^^
ValueError: attempt to get argmin of an empty sequence

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.