![]() |
VOOZH | about |
In this article, we will discuss how to load different kinds of data in PyTorch.
For demonstration purposes, Pytorch comes with 3 divisions of datasets namely torchaudio, torchvision, and torchtext. We can leverage these demo datasets to understand how to load Sound, Image, and text data using Pytorch.
Loading demo yes_no audio dataset in torchaudio using Pytorch.
Yes_No dataset is an audio waveform dataset, which has values stored in form of tuples of 3 values namely waveform, sample_rate, labels, where waveform represents the audio signal, sample_rate represents the frequency and label represent whether Yes or No.
To load your custom data:
Syntax: torch.utils.data.DataLoader(data, batch_size, shuffle)
Parameters:
- data - audio dataset or the path to the audio dataset
- batch_size - for large dataset, batch_size specifies how much data to load at once
- shuffle - a bool type. Setting it to True will shuffle the data.
Output:
Loading demo ImageNet vision dataset in torchvision using Pytorch. Click here to download the dataset by signing up.
Code Explanation:
To load your custom image data, use torch.utils.data.DataLoader(data, batch_size, shuffle) as mentioned above.
Output:
Image size: torch.Size([224,224]) tensor([0, 0, 0, 1, 1, 1])
Loading demo IMDB text dataset in torchtext using Pytorch. To load your custom text data we use torch.utils.data.DataLoader() method.
Syntax: torch.utils.data.DataLoader('path to/imdb_data', batch_size, shuffle=True)
Code Explanation:
Output: