You could create a “wrapper” dataset like this (not tested!):
class WrapperDataset(Dataset):
    def __init__(self, dataset, indices, transform=None):
         self.dataset = dataset
         self.indices = indices
         self.transform = transform
    def __len__(self):
        return len(self.indices)
    def __getitem__(self, idx):
        new_idx = self.indices[idx]
        data = self.dataset[new_idx]
        if self.transform is not None:
             ....
         return data

This way you can create two separate datasets for training/testing based on the indices you already have available.