@ptrblck Thanks for reply.
Can you please tell me how to use it in my code?
In my case, dataset is splitting in image wise not folder wise.
master= datasets.ImageFolder(data_dir,transform=train_transforms)

valid_size = 0.2
test_size = 0.2
num_train = len(master)
indices = list(range(num_train))
np.random.shuffle(indices)
valid_split = int(np.floor((valid_size) * num_train))
test_split = int(np.floor((valid_size+test_size) * num_train))
valid_idx, test_idx, train_idx = indices[:valid_split], indices[valid_split:test_split], indices[test_split:]

num_workers = 0
train_loader = torch.utils.data.DataLoader(train_idx, batch_size=64,
     num_workers=num_workers)
valid_loader = torch.utils.data.DataLoader(valid_idx, batch_size=64, 
     num_workers=num_workers)
test_loader = torch.utils.data.DataLoader(test_idx, batch_size=64, 
     num_workers=num_workers, shuffle=False)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")