Last active
March 14, 2021 13:43
-
-
Save ketanhdoshi/91a688e05b26536b1e4b249e8f77ed00 to your computer and use it in GitHub Desktop.
Create Data Loaders for Training and Validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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