Giter Site home page Giter Site logo

niuwk / continual_learning_data_former Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tlesort/continual_learning_data_former

0.0 1.0 0.0 1.33 MB

A pytorch compatible data loader to create sequence of tasks for Continual Learning

License: MIT License

Python 100.00%

continual_learning_data_former's Introduction

Continuum: A dataloader for continual learning

Codacy Badge DOI

Intro

This repositery proprose several script to create sequence of tasks for continual learning. The spirit is the following : Instead of managing the sequence of tasks while learning, we create the sequence of tasks first and then we load tasks one by one while learning.

It makes programming easier and code cleaner.

Installation

git clone https://github.com/TLESORT/Continual_Learning_Data_Former
cd Continual_Learning_Data_Former
pip install .

Few possible invocations

  • Disjoint tasks
from continuum.disjoint import Disjoint

#MNIST with 10 tasks of one class
continuum = Disjoint(path="./Data", dataset="MNIST", task_number=10, download=True, train=True)
  • Rotations tasks
from continuum.rotations import Rotations

#MNIST with 5 tasks with various rotations
continuum = Rotations(path="./Data", dataset="MNIST", tasks_number=5, download=True, train=True, min_rot=0.0,
                 max_rot=90.0)
  • Permutations tasks
from continuum.permutations import Permutations

#MNIST with 5 tasks with different permutations
continuum = Permutations(path="./Data", dataset="MNIST", tasks_number=1, download=False, train=True)

Use example

from continuum.disjoint import Disjoint
from torch.utils import data

# create continuum dataset
continuum = Disjoint(path=".", dataset="MNIST", task_number=10, download=True, train=True)

# create pytorch dataloader
train_loader = data.DataLoader(data_set, batch_size=64, shuffle=True, num_workers=6)

#set the task on 0 for example with the data_set
continuum.set_task(0)

# iterate on task 0
for t, (data, target) in enumerate(train_loader):
    print(target)
    
#change the task to 2 for example
continuum.set_task(2)

# iterate on task 2
for t, (data, target) in enumerate(train_loader):
    print(target)

# We can visualize samples from the sequence of tasks
for i in range(10):
    continuum.set_task(i)
    
    folder = "./Samples/disjoint_10_tasks/"
    
    if not os.path.exists(folder):
        os.makedirs(folder)
    
    path_samples = os.path.join(folder, "MNIST_task_{}.png".format(i))
    continuum.visualize_sample(path_samples , number=100, shape=[28,28,1])
    

Task sequences possibilities

  • Disjoint tasks : each task propose new classes
  • Rotations tasks : each tasks propose same data but with different rotations of datata point
  • Permutations tasks : each tasks propose same data but with different permutations of pixels
  • Mnist Fellowship task : each task is a new mnist like dataset (this sequence of task is an original contribution of this repository)

An example with MNIST 5 dijoint tasks

Task 0 Task 1 Task 2 Task 3 Task 4

More examples at Samples

Datasets

  • Mnist
  • fashion-Mnist
  • kmnist
  • cifar10
  • Core50/Core10

Some supplementary option are possible

  • The number of tasks can be choosed (1, 3, 5 and 10 have been tested normally)
  • Classes order can be shuffled for disjoint tasks
  • We can choose the magnitude of rotation for rotations mnist

Citing the Project

@software{timothee_lesort_2020_3605202,
  author       = {Timothée LESORT},
  title        = {Continual Learning Data Former},
  month        = jan,
  year         = 2020,
  publisher    = {Zenodo},
  version      = {v1.0},
  doi          = {10.5281/zenodo.3605202},
  url          = {https://doi.org/10.5281/zenodo.3605202}
}

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.