Have you tried torch.utils.data.ConcatDataset 5 to concat the two datasets?
I haven’t used it before, but I think it’s for this need?
By the way, the you are returning the concat of one training data and one testing data in your __getitem__ method, thus you get an error since the training dataset is larger than the testing dataset.
And if you code it this way, the length of the new dataset will not be the sum of two datasets.