How to load all 5 batches of CIFAR10 in a single data structure as on MNIST in PyTorch?
With Mnist I have a single file with the labels and a single file for the train, so I simply do:

self.data = datasets.MNIST(root='./data', train=True, download=True)


Basically I create a set of labels (from 0-9) and save the i-th position of the image in the data structure, to create my custom tasks:

   def make_tasks (self):
            self.task_to_examples = {} #task 0-9
            self.all_tasks = set (self.data.train_labels.numpy ())
            for i, digit in enumerate (self.data.train_labels.numpy ()):
                if str(digit) not in self.task_to_examples:
                    self.task_to_examples[str(digit)] = []
                self.task_to_examples[str(digits)].append(i)


I don't understand how to do the same thing using CIFAR10 because it is divided into 5 batches, I would like all the data in a single structure.

If your desired structure is {"class_id": [indices of the samples]}, then for CIFAR10 you can do something like this:

import numpy as np
import torchvision

# set root accordingly
cifar = torchvision.datasets.CIFAR10(root=".", train=True, download=True)
task_to_examples = {
    str(task_id): np.where(cifar.targets == task_id)[0].tolist()
    for task_id in np.unique(cifar.targets)
}


