Skip to content

Instantly share code, notes, and snippets.

@ketanhdoshi
Last active March 14, 2021 13:43
Show Gist options
  • Save ketanhdoshi/91a688e05b26536b1e4b249e8f77ed00 to your computer and use it in GitHub Desktop.
Save ketanhdoshi/91a688e05b26536b1e4b249e8f77ed00 to your computer and use it in GitHub Desktop.
Create Data Loaders for Training and Validation
from torch.utils.data import random_split
myds = SoundDS(df, data_path)
# Random split of 80:20 between training and validation
num_items = len(myds)
num_train = round(num_items * 0.8)
num_val = num_items - num_train
train_ds, val_ds = random_split(myds, [num_train, num_val])
# Create training and validation data loaders
train_dl = torch.utils.data.DataLoader(train_ds, batch_size=16, shuffle=True)
val_dl = torch.utils.data.DataLoader(val_ds, batch_size=16, shuffle=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment