Last active
August 4, 2020 03:38
-
-
Save syaffers/f39e901d1b084f4b1169cc88d1f50839 to your computer and use it in GitHub Desktop.
The third iteration of the numbers dataset now with multiple data output types
This file contains hidden or 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 Dataset | |
import torch | |
class NumbersDataset(Dataset): | |
def __init__(self, low, high): | |
self.samples = list(range(low, high)) | |
def __len__(self): | |
return len(self.samples) | |
def __getitem__(self, idx): | |
n = self.samples[idx] | |
successors = torch.arange(4).float() + n + 1 | |
noisy = torch.randn(4) + successors | |
return str(n), successors, noisy | |
if __name__ == '__main__': | |
from torch.utils.data import DataLoader | |
dataset = NumbersDataset(100, 120) | |
dataloader = DataLoader(dataset, batch_size=10, shuffle=True) | |
print(next(iter(dataloader))) |
@susheemmaurya π― You're right! Must've slipped past the radar π . Updated the code. Hope you're enjoying the article.
Yes @syaffers! I loved it, never seen a code which is so elegant. Also the article alongside was beautifully crafted.
Kudos pal!
@abhirupkamath Thanks dude! Much appreciated π
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please run this code again, it ain't returning a string pal.