Hi,
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 = Image.open(self.data_list[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!