A PyTorch implementation of the continual learning experiments with deep neural networks

Overview

Brain-Inspired Replay

A PyTorch implementation of the continual learning experiments with deep neural networks described in the following paper:

This paper proposes a new, brain-inspired version of generative replay that can scale to continual learning problems with natural images as inputs. This is demonstrated with the Split CIFAR-100 protocol, both for task-incremental learning and for class-incremental learning.

Installation & requirements

The current version of the code has been tested with Python 3.5.2 on several Linux operating systems with the following versions of PyTorch and Torchvision:

  • pytorch 1.1.0
  • torchvision 0.2.2

The versions that were used for other Python-packages are listed in requirements.txt.

To use the code, download the repository and change into it:

git clone https://github.com/GMvandeVen/brain-inspired-replay.git
cd brain-inspired-replay

(If downloading the zip-file, extract the files and change into the extracted folder.)

Assuming Python and pip are set up, the Python-packages used by this code can be installed using:

pip install -r requirements.txt

However, you might want to install pytorch and torchvision in a slightly different way to ensure compatability with your version of CUDA (see https://pytorch.org/).

Finally, the code in this repository itself does not need to be installed, but a number of scripts should be made executable:

chmod +x main_*.py compare_*.py create_figures.sh

Demos

Demo 1: Brain-inspired replay on split MNIST

./main_cl.py --experiment=splitMNIST --scenario=class --replay=generative --brain-inspired --pdf

This runs a single continual learning experiment: brain-inspired replay on the class-incremental learning scenario of split MNIST. Information about the data, the model, the training progress and the produced outputs (e.g., a pdf with results) is printed to the screen. Expected run-time on a standard laptop is ~12 minutes, with a GPU it should take ~4 minutes.

Demo 2: Comparison of continual learning methods

./compare_MNIST.py --scenario=class

This runs a series of continual learning experiments to compare the performance of various methods. Information about the different experiments, their progress and the produced outputs (e.g., a summary pdf) is printed to the screen. Expected run-time on a standard laptop is ~50 minutes, with a GPU it should take ~18 minutes.

These two demos can also be run with on-the-fly plots using the flag --visdom. For this visdom must be activated first, see instructions below.

Running comparisons from the paper

The script create_figures.sh provides step-by-step instructions for re-running the experiments and re-creating the figures reported in the paper.

Although it is possible to run this script as it is, it will take very long and it is probably sensible to parallellize the experiments.

Running custom experiments

Using main_cl.py, it is possible to run custom individual experiments. The main options for this script are:

  • --experiment: which task protocol? (splitMNIST|permMNIST|CIFAR100)
  • --scenario: according to which scenario? (task|domain|class)
  • --tasks: how many tasks?

To run specific methods, use the following:

  • Context-dependent-Gating (XdG): ./main_cl.py --xdg --xdg-prop=0.8
  • Elastic Weight Consolidation (EWC): ./main_cl.py --ewc --lambda=5000
  • Online EWC: ./main_cl.py --ewc --online --lambda=5000 --gamma=1
  • Synaptic Intelligenc (SI): ./main_cl.py --si --c=0.1
  • Learning without Forgetting (LwF): ./main_cl.py --replay=current --distill
  • Generative Replay (GR): ./main_cl.py --replay=generative
  • Brain-Inspired Replay (BI-R): ./main_cl.py --replay=generative --brain-inspired

For information on further options: ./main_cl.py -h.

PyTorch-implementations for several methods relying on stored data (Experience Replay, iCaRL and A-GEM), as well as for additional metrics (FWT, BWT, forgetting, intransigence), can be found here: https://github.com/GMvandeVen/continual-learning.

On-the-fly plots during training

With this code it is possible to track progress during training with on-the-fly plots. This feature requires visdom. Before running the experiments, the visdom server should be started from the command line:

python -m visdom.server

The visdom server is now alive and can be accessed at http://localhost:8097 in your browser (the plots will appear there). The flag --visdom should then be added when calling ./main_cl.py to run the experiments with on-the-fly plots.

For more information on visdom see https://github.com/facebookresearch/visdom.

Citation

Please consider citing our paper if you use this code in your research:

@article{vandeven2020brain,
  title={Brain-inspired replay for continual learning with artificial neural networks},
  author={van de Ven, Gido M and Siegelmann, Hava T and Tolias, Andreas S},
  journal={Nature Communications},
  volume={11},
  pages={4069},
  year={2020}
}

Acknowledgments

The research project from which this code originated has been supported by an IBRO-ISN Research Fellowship, by the Lifelong Learning Machines (L2M) program of the Defence Advanced Research Projects Agency (DARPA) via contract number HR0011-18-2-0025 and by the Intelligence Advanced Research Projects Activity (IARPA) via Department of Interior/Interior Business Center (DoI/IBC) contract number D16PC00003. Disclaimer: views and conclusions contained herein are those of the authors and should not be interpreted as necessarily representing the official policies or endorsements, either expressed or implied, of DARPA, IARPA, DoI/IBC, or the U.S. Government.

Comments
  • Unable to reproduce the results

    Unable to reproduce the results

    Hello,

    Sorry to bug you, but I think I am unable to reproduce the results.

    Check out my notebook, https://colab.research.google.com/drive/1g55JOiJnFRsTB7kjqkJO9YykTy1JDHhm?usp=sharing

    I am trying to reproduce results on Class-IL for EWC and LWF for 10 tasks. I saw in your article that for 10 classes LWF and EWC get higher accuracy than I am able to achieve. Am I doing something wrong?

    Great work though!

    opened by puneater 13
  • Precision or Accuracy?

    Precision or Accuracy?

    When I run the experiments, it displays as follows:

    | Task: 3/5 | training loss: 0.407 | training precision: 0.992 |: 100%|███████████████████████████████████| 2000/2000 [08:37<00:00, 3.87it/s]

    On-the-fly visdom plots also show precision as y-axis but the title of the plot is average accuracy.

    Can you please clarify on that? I have seen same confusion in the code of your other repo: https://github.com/GMvandeVen/continual-learning

    opened by kaustubholpadkar 4
  • command to run baselines

    command to run baselines

    Hi, I am really amazed by the number of options that are being provided in the code to run the experiments. I was wondering how to run the baselines, that is, Joint Training and None [simple sequential learning], as mentioned in the article. What is the code and the parameters to run these baseline algorithms seperately, like we can run algorithms like GR, LWF, etc?

    opened by puneater 2
  • pre-trained model

    pre-trained model

    Hi, I want to ask about the pre-trained models. The paper says you pre-train on cifar10, but the default pre-trained model, in the store/models/ file, C3-5×16-bn, seems a model of pre-training on cifar100. I have run main_pretrain.py on cifar10 to change the pre-trained model and it worked worse than the default. Did you use pre-trained model of cifar100 rather than cifar10 on paper's experiments?

    opened by leatherking 2
  • Can't run cmopare_permMNIST100_bir.py

    Can't run cmopare_permMNIST100_bir.py

    Hi, When I ran compare_permMNIST100_bir.py, and set --seed=12 --n-seeds=5. Then an error occureed,

    File "/media/wuya/DATA/Code/continual_learning/brain-inspired-replay/options.py", line 350, in set_defaults args.xdg_prop = 0. if args.scenario=="task" and args.xdg_prop is None else args.xdg_prop AttributeError: 'Namespace' object has no attribute 'xdg_prop'

    I don't know where to set xdg_prop, can you tell me how to do it? Thank you very much!

    Screenshot from 2021-02-03 00-23-12

    opened by AIwuya 2
  • result for 'scenario = class'

    result for 'scenario = class'

    Hi, I am learning on your codes for a week and I have run several experiments so far. I have some questions.

    1. The setting of 'scenario='task'' works well, but the other one of 'scenario=class' is what I am confused with : For example, if I set a setting: 'expri..=splitMNIST, tasks=5, scenario=class ' , the result is "-task1: xx. xx -task2: xx. xx task3: xx. xx -task4: xx. xx -task5: xx. xx". I don't understand what it means as the result format is the same with 'scenario=task'. Does the classifier uses single-head or multi-head for class-IL ?

    2. In my experiments, EWC, SI, LwF had no effect on class-IL , all forgot. Is it normal?

    Best regard

    opened by leatherking 2
  • Regarding the

    Regarding the "reinitialization of networks"

    Hi, I refer to Fig 4 of the main paper, where it states "As a control, also shown is a variant of generative replay whereby the networks are reinitialized before each new task/episode". By reinitialization, does this mean that if we have that model after trained on task1, if we have to train on the next task, then we create a "brand new" model with the exact same architecture and retrain? If it is, then how different will it be from retraining from the current model? Is it likely that there will be no difference in performance with and without reinitialization for other cases because I tried on other types of dataset and the 2 curves kind of overlap rather than show one is better than the other?

    opened by hockman1 2
  • How to reload model and predict?

    How to reload model and predict?

    Hi GMvandeVen, the model will be saved after run ./main_cl.py --experiment=splitMNIST --scenario=class --replay=generative --brain-inspired --pdf

    is there any command to load trained model and use the model to predict?

    opened by pardont 2
  • Bump numpy from 1.16.2 to 1.22.0

    Bump numpy from 1.16.2 to 1.22.0

    Bumps numpy from 1.16.2 to 1.22.0.

    Release notes

    Sourced from numpy's releases.

    v1.22.0

    NumPy 1.22.0 Release Notes

    NumPy 1.22.0 is a big release featuring the work of 153 contributors spread over 609 pull requests. There have been many improvements, highlights are:

    • Annotations of the main namespace are essentially complete. Upstream is a moving target, so there will likely be further improvements, but the major work is done. This is probably the most user visible enhancement in this release.
    • A preliminary version of the proposed Array-API is provided. This is a step in creating a standard collection of functions that can be used across application such as CuPy and JAX.
    • NumPy now has a DLPack backend. DLPack provides a common interchange format for array (tensor) data.
    • New methods for quantile, percentile, and related functions. The new methods provide a complete set of the methods commonly found in the literature.
    • A new configurable allocator for use by downstream projects.

    These are in addition to the ongoing work to provide SIMD support for commonly used functions, improvements to F2PY, and better documentation.

    The Python versions supported in this release are 3.8-3.10, Python 3.7 has been dropped. Note that 32 bit wheels are only provided for Python 3.8 and 3.9 on Windows, all other wheels are 64 bits on account of Ubuntu, Fedora, and other Linux distributions dropping 32 bit support. All 64 bit wheels are also linked with 64 bit integer OpenBLAS, which should fix the occasional problems encountered by folks using truly huge arrays.

    Expired deprecations

    Deprecated numeric style dtype strings have been removed

    Using the strings "Bytes0", "Datetime64", "Str0", "Uint32", and "Uint64" as a dtype will now raise a TypeError.

    (gh-19539)

    Expired deprecations for loads, ndfromtxt, and mafromtxt in npyio

    numpy.loads was deprecated in v1.15, with the recommendation that users use pickle.loads instead. ndfromtxt and mafromtxt were both deprecated in v1.17 - users should use numpy.genfromtxt instead with the appropriate value for the usemask parameter.

    (gh-19615)

    ... (truncated)

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • xdg_prop attribute

    xdg_prop attribute

    Perhaps related to 9afa20f14, I get:

    ./compare_MNIST_hyperParams.py --scenario=task --seed=11                 #--> Fig. S1 (top)
    Traceback (most recent call last):
      File "./compare_MNIST_hyperParams.py", line 62, in <module>
        args = handle_inputs()
      File "./compare_MNIST_hyperParams.py", line 37, in handle_inputs
        options.set_defaults(args, **kwargs)
      File "/home/fcyb/projects/brain-inspired-replay/options.py", line 350, in set_defaults
        args.xdg_prop = 0. if args.scenario=="task" and args.xdg_prop is None else args.xdg_prop
    AttributeError: 'Namespace' object has no attribute 'xdg_prop'
    

    Seems in hyper compare mode, xdg_prop is never defined? https://github.com/GMvandeVen/brain-inspired-replay/blob/e9694e854429cc33c4ccb352a75099cc8d55ee4c/options.py#L259-L260

    opened by benureau 1
  • where i got confuse

    where i got confuse

    https://github.com/GMvandeVen/brain-inspired-replay/blob/ae102358855c9b0512fcf7851c12c5354ef2ab1f/models/vae.py#L761 i don"t understand why how can use like that ,there are no function infer.

    opened by luyifanlu 1
  • Allowing an option to reproduce the code but on arbitrary datasets

    Allowing an option to reproduce the code but on arbitrary datasets

    Hi is it possible to allow an option for users to input their own dataset into the model rather than the default CIFAR10 and MNIST? If not, is there a minimal way that we can modify the scripts to accommodate our own datasets, especially inputs that are not image based , eg 1D arrays? Thanks!!!

    opened by hockman1 9
Owner
Working at the intersection of Machine Learning, Computational Neuroscience and Cognitive Science.
null
Code to reproduce the experiments from our NeurIPS 2021 paper " The Limitations of Large Width in Neural Networks: A Deep Gaussian Process Perspective"

Code To run: python runner.py new --save <SAVE_NAME> --data <PATH_TO_DATA_DIR> --dataset <DATASET> --model <model_name> [options] --n 1000 - train - t

Geoff Pleiss 5 Dec 12, 2022
A general framework for deep learning experiments under PyTorch based on pytorch-lightning

torchx Torchx is a general framework for deep learning experiments under PyTorch based on pytorch-lightning. TODO list gan-like training wrapper text

Yingtian Liu 6 Mar 17, 2022
Pytorch Implementation of Continual Learning With Filter Atom Swapping (ICLR'22 Spolight) Paper

Continual Learning With Filter Atom Swapping Pytorch Implementation of Continual Learning With Filter Atom Swapping (ICLR'22 Spolight) Paper If find t

null 11 Aug 29, 2022
Official Pytorch implementation of Online Continual Learning on Class Incremental Blurry Task Configuration with Anytime Inference (ICLR 2022)

The Official Implementation of CLIB (Continual Learning for i-Blurry) Online Continual Learning on Class Incremental Blurry Task Configuration with An

NAVER AI 34 Oct 26, 2022
An implementation demo of the ICLR 2021 paper Neural Attention Distillation: Erasing Backdoor Triggers from Deep Neural Networks in PyTorch.

Neural Attention Distillation This is an implementation demo of the ICLR 2021 paper Neural Attention Distillation: Erasing Backdoor Triggers from Deep

Yige-Li 84 Jan 4, 2023
PyTorch implementation of the supervised learning experiments from the paper Model-Agnostic Meta-Learning (MAML)

pytorch-maml This is a PyTorch implementation of the supervised learning experiments from the paper Model-Agnostic Meta-Learning (MAML): https://arxiv

Kate Rakelly 516 Jan 5, 2023
[CVPR2022] Representation Compensation Networks for Continual Semantic Segmentation

RCIL [CVPR2022] Representation Compensation Networks for Continual Semantic Segmentation Chang-Bin Zhang1, Jia-Wen Xiao1, Xialei Liu1, Ying-Cong Chen2

Chang-Bin Zhang 71 Dec 28, 2022
PyTorch implementation of: Michieli U. and Zanuttigh P., "Continual Semantic Segmentation via Repulsion-Attraction of Sparse and Disentangled Latent Representations", CVPR 2021.

Continual Semantic Segmentation via Repulsion-Attraction of Sparse and Disentangled Latent Representations This is the official PyTorch implementation

Multimedia Technology and Telecommunication Lab 42 Nov 9, 2022
PyTorch Personal Trainer: My framework for deep learning experiments

Alex's PyTorch Personal Trainer (ptpt) (name subject to change) This repository contains my personal lightweight framework for deep learning projects

Alex McKinney 8 Jul 14, 2022
CL-Gym: Full-Featured PyTorch Library for Continual Learning

CL-Gym: Full-Featured PyTorch Library for Continual Learning CL-Gym is a small yet very flexible library for continual learning research and developme

Iman Mirzadeh 36 Dec 25, 2022
Cl datasets - PyTorch image dataloaders and utility functions to load datasets for supervised continual learning

Continual learning datasets Introduction This repository contains PyTorch image

berjaoui 5 Aug 28, 2022
Bayesian-Torch is a library of neural network layers and utilities extending the core of PyTorch to enable the user to perform stochastic variational inference in Bayesian deep neural networks

Bayesian-Torch is a library of neural network layers and utilities extending the core of PyTorch to enable the user to perform stochastic variational inference in Bayesian deep neural networks. Bayesian-Torch is designed to be flexible and seamless in extending a deterministic deep neural network architecture to corresponding Bayesian form by simply replacing the deterministic layers with Bayesian layers.

Intel Labs 210 Jan 4, 2023
Algorithmic trading with deep learning experiments

Deep-Trading Algorithmic trading with deep learning experiments. Now released part one - simple time series forecasting. I plan to implement more soph

Alex Honchar 1.4k Jan 2, 2023
TorchOk - The toolkit for fast Deep Learning experiments in Computer Vision

TorchOk - The toolkit for fast Deep Learning experiments in Computer Vision

null 52 Dec 23, 2022
Official code of CVPR 2021's PLOP: Learning without Forgetting for Continual Semantic Segmentation

PLOP: Learning without Forgetting for Continual Semantic Segmentation This repository contains all of our code. It is a modified version of Cermelli e

Arthur Douillard 116 Dec 14, 2022
Avalanche RL: an End-to-End Library for Continual Reinforcement Learning

Avalanche RL: an End-to-End Library for Continual Reinforcement Learning Avalanche Website | Getting Started | Examples | Tutorial | API Doc | Paper |

ContinualAI 43 Dec 24, 2022
Complex-Valued Neural Networks (CVNN)Complex-Valued Neural Networks (CVNN)

Complex-Valued Neural Networks (CVNN) Done by @NEGU93 - J. Agustin Barrachina Using this library, the only difference with a Tensorflow code is that y

youceF 1 Nov 12, 2021
A framework that constructs deep neural networks, autoencoders, logistic regressors, and linear networks

A framework that constructs deep neural networks, autoencoders, logistic regressors, and linear networks without the use of any outside machine learning libraries - all from scratch.

Kordel K. France 2 Nov 14, 2022
A PyTorch implementation of Multi-digit Number Recognition from Street View Imagery using Deep Convolutional Neural Networks

SVHNClassifier-PyTorch A PyTorch implementation of Multi-digit Number Recognition from Street View Imagery using Deep Convolutional Neural Networks If

Potter Hsu 182 Jan 3, 2023