Re-arrange MNIST into two classes

I want to re-arrange the MNIST into to 2 classes - odd numbers in one class and even numbers in another class, then use this rearranged dataset for train and test. How to do it?

You could try to adapt this code for your use case.

1 Like

I will try it and get back.

@ptrblck The following works for me. Thanks :slight_smile:

for i in range(10):
  idx = (dataset.targets==i)
  if (i == 0) or ((i % 2) == 0): dataset.targets[idx] = 0

  else: dataset.targets[idx] = 1
1 Like