How to separate pytorch MNIST dataset into n subsets containing 2 classes each?

Hello,

I am trying to separate pytorch MNIST dataset into n subsets each containing data from only 2 classes and then save the n subsets in differents files to load them later.

For example, subset 0 will contain images of class 0 and 1 (corresponding to the MNIST classes), subset 1 will contain images of class 1 and 2 and so on up to subset n.

If n is bigger than the number of classes several subsets will contain the same classes combination, ex: subset 10 can also contain images from class 0 and 1.

But every datapoint is given to only one subset, the same data point can not be in subset 0 and 10 for example.

I tried to write a code that does that using torch.utils.data.random_split and torch.utils.data.ConcatDataset but strangely in the files I save there always is the same data…

Thank you for your Help,

Double post from here.
Did you try to debug your code and check where the wrong entries come from?