Issue
I am having data of numpy arrays with shape (400, 46, 55, 46)
here 400 are the samples and 46,55,46
is the image.350 samples for training and remaining 50 for validation
np.max(data[1]), np.min(data[1]), len(data[1])
Output: (2941.0, -43.0, 46)
Now i want to load the data into pytorch model for that i need to write a custom dataloader as i am new to pytorch i am finding hard to wrie can someone help
Solution
You can use a combination of torch.utils.data.TensorData
and torch.utils.data.random_split
to construct the two datasets and wrap them with torch.utils.data.DataLoader
:
>>> data = np.random.rand(400, 46, 55, 46)
# Datasets initialization
>>> ds = TensorDataset(torch.from_numpy(data))
>>> train_ds, valid_ds = random_split(ds, (350, 50))
# Dataloader wrappers
>>> train_dl, valid_dl = DataLoader(train_ds), DataLoader(valid_ds)
Answered By - Ivan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.