-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfast_mnist.py
26 lines (20 loc) · 977 Bytes
/
fast_mnist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import torch
from torchvision.datasets import MNIST, FashionMNIST
class FastMNIST(MNIST):
def __init__(self, *args, **kwargs):
device = kwargs.pop('device', None)
super().__init__(*args, **kwargs)
#device = 'cuda' if torch.cuda.is_available() else 'cpu'
self.data = self.data.unsqueeze(1).double().div(255)
self.data, self.targets = self.data.to(device), self.targets.to(device)
def __getitem__(self, index):
return self.data[index], self.targets[index]
class FastFashionMNIST(FashionMNIST):
def __init__(self, *args, **kwargs):
device = kwargs.pop('device', None)
super().__init__(*args, **kwargs)
#device = 'cuda' if torch.cuda.is_available() else 'cpu'
self.data = self.data.unsqueeze(1).double().div(255)
self.data, self.targets = self.data.to(device), self.targets.to(device)
def __getitem__(self, index):
return self.data[index], self.targets[index]