Skip to main content

Continual Loader (CLLoader)

PyPI version Build Status

A library for PyTorch's loading of datasets in the field of Continual Learning

Aka Continual Learning, Lifelong-Learning, Incremental Learning, etc.

Example:

Install from and PyPi:

pip3 install clloader

And run!

from torch.utils.data import DataLoader

from clloader import CLLoader
from clloader.datasets import MNIST

clloader = CLLoader(
    MNIST("my/data/path", download=True),
    increment=1,
    initial_increment=5
)

print(f"Number of classes: {clloader.nb_classes}.")
print(f"Number of tasks: {clloader.nb_tasks}.")

for task_id, (train_dataset, test_dataset) in enumerate(clloader):
    train_loader = DataLoader(train_dataset)
    test_loader = DataLoader(test_dataset)

    # Do your cool stuff here

Supported Scenarios

Name Acronym  Supported
New Instances  NI ❌
New Classes  NC ✅
New Instances & Classes  NIC ❌

Supported Datasets:

Note that the task sizes are fully customizable.

Name Nb classes  Image Size Automatic Download
MNIST 10  28x28x1 ✅
Fashion MNIST 10  28x28x1 ✅
KMNIST 10  28x28x1 ✅
EMNIST 10  28x28x1 ✅
QMNIST 10  28x28x1 ✅
MNIST Fellowship 30  28x28x1 ✅
CIFAR10 10 32x32x3 ✅
CIFAR100 100 32x32x3 ✅
CIFAR Fellowship 110 32x32x3 ✅
ImageNet100 100 224x224x3 ❌
ImageNet1000 1000 224x224x3 ❌
Permuted MNIST 10 28x28x1 ✅
Rotated MNIST 10 28x28x1 ✅

Furthermore some "Meta"-datasets are available:

InMemoryDataset, for in-memory numpy array:

x_train, y_train = gen_numpy_array()
x_test, y_test = gen_numpy_array()

clloader = CLLoader(
    InMemoryDataset(x_train, y_train, x_test, y_test),
    increment=10,
)

PyTorchDataset,for any dataset defined in torchvision:

clloader = CLLoader(
    PyTorchDataset("/my/data/path", dataset_type=torchvision.datasets.CIFAR10),
    increment=10,
)

ImageFolderDataset, for datasets having a tree-like structure, with one folder per class:

clloader = CLLoader(
    ImageFolderDataset("/my/train/folder", "/my/test/folder"),
    increment=10,
)

Fellowship, to combine several continual datasets.:

clloader = CLLoader(
    Fellowship("/my/data/path", dataset_list=[CIFAR10, CIFAR100]),
    increment=10,
)

Some datasets cannot provide an automatic download of the data for miscealleneous reasons. For example for ImageNet, you'll need to download the data from the official page. Then load it likewise:

clloader = CLLoader(
    ImageNet1000("/my/train/folder", "/my/test/folder"),
    increment=10,
)

Some papers use a subset, called ImageNet100 or ImageNetSubset. You'll need to get the subset ids. It's either a file in the following format:

my/path/to/image0.JPEG target0
my/path/to/image1.JPEG target1

Or a list of tuple [("my/path/to/image0.JPEG", target0), ...]. Then loading the continual loader is very simple:

clloader = CLLoader(
    ImageNet100(
        "/my/train/folder",
        "/my/test/folder",
        train_subset=... # My subset ids
        test_subset=... # My subset ids
    ),
    increment=10,
)

Continual Loader

The Continual Loader CLLoader loads the data and batch it in several tasks. See there some example arguments:

clloader = CLLoader(
    my_continual_dataset,
    increment=10,
    initial_increment=2,
    train_transformations=[transforms.RandomHorizontalFlip()],
    common_transformations=[
        transforms.ToTensor(),
        transforms.Normalize((0.4914, 0.4822, 0.4465), (0.2023, 0.1994, 0.2010))
    ],
    evaluate_on="seen"
)

Here the first task is made of 2 classes, then all following tasks of 10 classes. You can have a more finegrained increment by providing a list of ìncrement=[2, 10, 5, 10]`.

The train_transformations is applied only on the training data, while the common_transformations on both the training and testing data.

By default, we evaluate our model after each task on seen classes. But you can evalute only on current classes, or even on all classes.

Sample Images

MNIST:

Task 0 Task 1 Task 2 Task 3 Task 4

FashionMNIST:

Task 0 Task 1 Task 2 Task 3 Task 4

CIFAR10:

Task 0 Task 1 Task 2 Task 3 Task 4

MNIST Fellowship (MNIST + FashionMNIST + KMNIST):

Task 0 Task 1 Task 2

PermutedMNIST:

Task 0 Task 1 Task 2 Task 3 Task 4

Metadata

Release files for clloader 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for clloader 0.0.2
File Size Uploaded Provenance Actions
clloader-0.0.2.tar.gz 414.7 kB Without provenance Details for clloader-0.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for clloader 0.0.2
File Interpreter ABI Platform Actions
clloader-0.0.2-py3-none-any.whl Python 3 none any Details for clloader-0.0.2-py3-none-any.whl

Total release size: 430.1 kB

Release files / clloader-0.0.2.tar.gz

Download URL clloader-0.0.2.tar.gz
Size 414.7 kB
Tags Source
SHA-256 checksum
How to use checksums
aafb30f3e120e539ff8fe74d3fd47672e73801cab7bc106ffebfb207fe6b4a5b
BLAKE2b-256 checksum
How to use checksums
af10b1bddcc8220562151ec02b664858810c23ff3c02b21cf71cfdd685a6e350
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.6

Release files / clloader-0.0.2-py3-none-any.whl

Download URL clloader-0.0.2-py3-none-any.whl
Size 15.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fdfbeef3e0b41223ce80235c356dbcafedcefc27dccbdb1c6177399c666c70db
BLAKE2b-256 checksum
How to use checksums
f777b89997f30222756d0e83990c35c390aff82b33bfa8296bf0a8eca172fc41
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.6

Security for clloader 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page