I want to train MNIST first on only 0’s and 1’s, then next on 0,1 and 2 only and then next on 0,1,2, and 3 only and so on until I am training on the entire dataset. How to do this?
You could recreate the dataset using this code snippet as a starter.
PS: Please don’t tag people in general, as this might demotivate others to post a better answer.
2 Likes
You can calculate all the indexes first to avoid rewriting and reloading the data again.
train_Indexs=[]
for i in range(10) :train_Indexs.append([] )
test_Indexs = []
for i in range(10) :test_Indexs.append([] )
for num in range(0,len(trainset.labels)):
train_Indexs[trainset.labels[num]].append(num)
for num in range(0,len(testset.labels)):
test_Indexs[testset.labels[num]].append(num)
index_train=train_Indexs[0]#the class u want
modified_train_labels = [1 if (trainset.train_labels[x] in postive_class) else 0 for x in index_train]#if you want to modify the label
trainset.train_labels=modified_train_labels#train set labels
trainset.train_data=trainset.train_data[index_train]#train set data
1 Like