22.02.2024 Views

Daniel Voigt Godoy - Deep Learning with PyTorch Step-by-Step A Beginner’s Guide-leanpub

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Transformed Dataset

1 class TransformedTensorDataset(Dataset):

2 def __init__(self, x, y, transform=None):

3 self.x = x

4 self.y = y

5 self.transform = transform

6

7 def __getitem__(self, index):

8 x = self.x[index]

9

10 if self.transform:

11 x = self.transform(x)

12

13 return x, self.y[index]

14

15 def __len__(self):

16 return len(self.x)

A Multiclass Classification Problem | 373

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!