0
votes

Is it possible to split a dataloader object of training dataset into training and validation dataloader?

from torch.utils.data import DataLoader
from torchvision import datasets, transforms

train_dataset = datasets.ImageFolder(train_data_directory, transform=transforms.ToTensor())
# Data loader
train_loader = DataLoader(train_dataset, batch_size=100, shuffle=True)

Now I would like to split a train_loader to train and validation dataloader.

1

1 Answers

0
votes

Look at random_split in torch.utils.data. It will handle a random Dataset split (you have to split before creating the DataLoader, not after).