Saving back dataloader content

I used randome distribution to distribute data between validation and data sets. Now, for further tests, I need to save the images that are selected in validation set. Is it possible to save the images from dataset with the same name?

validation_split = 0.2
shuffle_dataset = True
random_seed= 42

Creating data indices for training and validation splits:

dataset_size = len(train_dataset)
indices = list(range(dataset_size))
split = int(np.floor(validation_split * dataset_size))
if shuffle_dataset :
train_indices, val_indices = indices[split:], indices[:split]

Creating PT data samplers and loaders:

train_sampler = SubsetRandomSampler(train_indices)
valid_sampler = SubsetRandomSampler(val_indices)


I think we could add a custom dataset to get training samples, validation samples and their filenames based on your works.

class MyDataset(Dataset):
    def __init__(self, dataset_path):
        super(MyDataset, self).__init__()
        self.data_list = glob.glob(os.path.join(dataset_path,'.png'))
    def __getitem__(self, index):
        data =[index])
        # assuming that img_name.png
        file_path = self.data_list[index].split('/')[-1].split('.')[0]
        return data, file_path
    def __len__(self):
        return len(self.data_list)
dataset = MyDataset(dataset_path)
train_dataloader = DataLoader(dataset, batch_size, shuffle=False, sampler = train_sampler)
valid_dataloader = DataLoader(dataset, batch_size, shuffle=False, sampler = train_sampler)

I think it may work, you can have a try on it and let me know!