MCPcopy Create free account
hub / github.com/OpenRL-Lab/Wandb_Tutorial / fashion

Class fashion

sweep/cnn/fashion_data.py:11–136  ·  view source on GitHub ↗

`MNIST `_ Dataset. Args: root (string): Root directory of dataset where ``processed/training.pt`` and ``processed/test.pt`` exist. train (bool, optional): If True, creates dataset from ``training.pt``, otherwise from ``t

Source from the content-addressed store, hash-verified

9
10
11class fashion(data.Dataset):
12 """`MNIST <http://yann.lecun.com/exdb/mnist/>`_ Dataset.
13 Args:
14 root (string): Root directory of dataset where ``processed/training.pt``
15 and ``processed/test.pt`` exist.
16 train (bool, optional): If True, creates dataset from ``training.pt``,
17 otherwise from ``test.pt``.
18 download (bool, optional): If true, downloads the dataset from the internet and
19 puts it in root directory. If dataset is already downloaded, it is not
20 downloaded again.
21 transform (callable, optional): A function/transform that takes in an PIL image
22 and returns a transformed version. E.g, ``transforms.RandomCrop``
23 target_transform (callable, optional): A function/transform that takes in the
24 target and transforms it.
25 """
26 urls = [
27 'http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-images-idx3-ubyte.gz',
28 'http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-labels-idx1-ubyte.gz',
29 'http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-images-idx3-ubyte.gz',
30 'http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-labels-idx1-ubyte.gz',
31 ]
32 raw_folder = 'raw'
33 processed_folder = 'processed'
34 training_file = 'training.pt'
35 test_file = 'test.pt'
36
37 def __init__(self, root, train=True, transform=None, target_transform=None, download=False):
38 self.root = os.path.expanduser(root)
39 self.transform = transform
40 self.target_transform = target_transform
41 self.train = train # training set or test set
42
43 if download:
44 self.download()
45
46 if not self._check_exists():
47 raise RuntimeError('Dataset not found.' +
48 ' You can use download=True to download it')
49
50 if self.train:
51 self.train_data, self.train_labels = torch.load(
52 os.path.join(root, self.processed_folder, self.training_file))
53 else:
54 self.test_data, self.test_labels = torch.load(os.path.join(root, self.processed_folder, self.test_file))
55
56 def __getitem__(self, index):
57 """
58 Args:
59 index (int): Index
60 Returns:
61 tuple: (image, target) where target is index of the target class.
62 """
63 if self.train:
64 img, target = self.train_data[index], self.train_labels[index]
65 else:
66 img, target = self.test_data[index], self.test_labels[index]
67
68 # doing this so that it is consistent with all other datasets

Callers 1

trainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected