Skip to content

Instantly share code, notes, and snippets.

@syaffers
Last active August 4, 2020 03:38
Show Gist options
  • Select an option

  • Save syaffers/f39e901d1b084f4b1169cc88d1f50839 to your computer and use it in GitHub Desktop.

Select an option

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
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

Copy link
Copy Markdown

Please run this code again, it ain't returning a string pal.

@syaffers

Copy link
Copy Markdown
Author

@susheemmaurya πŸ’― You're right! Must've slipped past the radar πŸ˜…. Updated the code. Hope you're enjoying the article.

@abeekmath

Copy link
Copy Markdown

Yes @syaffers! I loved it, never seen a code which is so elegant. Also the article alongside was beautifully crafted.
Kudos pal!

@syaffers

syaffers commented Aug 4, 2020

Copy link
Copy Markdown
Author

@abhirupkamath Thanks dude! Much appreciated 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment