Combine Train and Test data

What is the best way to combine train and test data in torchvision and how can we do it?

Can someone explain how can we do it using ConcatDataset ?

I tried the following:
train = datasets.MNIST(root=dirpath, train=True, download=True, transform=trans)
test = datasets.MNIST(root=dirpath, train=False, download=True, transform=trans)
data_list = list()
data_list.append(train)
data_list.append(test)
total = ConcatDataset(data_list)

But it did not work.

Did you get an error?
Your code should work.
Alternatively try this:

train_dataset = datasets.MNIST(root=dirpath, train=True, transform=trans)
test_dataset = datasets.MNIST(root=dirpath, train=False, transform=trans)

dataset = ConcatDataset([train_dataset, test_dataset])

Both codes should be equivalent, so let me know, if mine works.

1 Like