From b4a1043cc9d37336f8a1b7821008c73463e477dc Mon Sep 17 00:00:00 2001 From: Kashif Rasul Date: Sat, 2 Sep 2017 13:08:40 +0200 Subject: [PATCH 1/4] added FashionMNIST dataset --- torchvision/datasets/__init__.py | 4 ++-- torchvision/datasets/mnist.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/torchvision/datasets/__init__.py b/torchvision/datasets/__init__.py index fb72688af90..1edbc49d88f 100644 --- a/torchvision/datasets/__init__.py +++ b/torchvision/datasets/__init__.py @@ -3,7 +3,7 @@ from .coco import CocoCaptions, CocoDetection from .cifar import CIFAR10, CIFAR100 from .stl10 import STL10 -from .mnist import MNIST +from .mnist import MNIST, FashionMNIST from .svhn import SVHN from .phototour import PhotoTour from .fakedata import FakeData @@ -11,5 +11,5 @@ __all__ = ('LSUN', 'LSUNClass', 'ImageFolder', 'FakeData', 'CocoCaptions', 'CocoDetection', - 'CIFAR10', 'CIFAR100', + 'CIFAR10', 'CIFAR100', 'FashionMNIST', 'MNIST', 'STL10', 'SVHN', 'PhotoTour') diff --git a/torchvision/datasets/mnist.py b/torchvision/datasets/mnist.py index 94319fe5e01..dee28287bba 100644 --- a/torchvision/datasets/mnist.py +++ b/torchvision/datasets/mnist.py @@ -139,6 +139,17 @@ def download(self): print('Done!') +class FashionMNIST(MNIST): + """`Fashion MNIST `_ Dataset. + """ + urls = [ + 'http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-images-idx3-ubyte.gz', + 'http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-labels-idx1-ubyte.gz', + 'http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-images-idx3-ubyte.gz', + 'http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-labels-idx1-ubyte.gz', + ] + + def get_int(b): return int(codecs.encode(b, 'hex'), 16) From 61df57ec700350c86bf4cb531e3696e60a063f0f Mon Sep 17 00:00:00 2001 From: Kashif Rasul Date: Sat, 2 Sep 2017 13:17:06 +0200 Subject: [PATCH 2/4] documentation --- README.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index c6de582fb08..9f6221b3ef1 100644 --- a/README.rst +++ b/README.rst @@ -43,7 +43,7 @@ Datasets The following dataset loaders are available: -- `MNIST <#mnist>`__ +- `MNIST and FashionMNIST <#mnist>`__ - `COCO (Captioning and Detection) <#coco>`__ - `LSUN Classification <#lsun>`__ - `ImageFolder <#imagefolder>`__ @@ -77,6 +77,8 @@ MNIST ~~~~~ ``dset.MNIST(root, train=True, transform=None, target_transform=None, download=False)`` +``dset.FashionMNIST(root, train=True, transform=None, target_transform=None, download=False)`` + ``root``: root directory of dataset where ``processed/training.pt`` and ``processed/test.pt`` exist ``train``: ``True`` - use training set, ``False`` - use test set. From bba63bba002b607a39e64eeba84b9de01eee5d70 Mon Sep 17 00:00:00 2001 From: Kashif Rasul Date: Sat, 2 Sep 2017 13:21:39 +0200 Subject: [PATCH 3/4] fixed formatting --- README.rst | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.rst b/README.rst index 9f6221b3ef1..480b3edf6a0 100644 --- a/README.rst +++ b/README.rst @@ -392,32 +392,32 @@ For example: Utils ===== -make\_grid(tensor, nrow=8, padding=2, normalize=False, range=None, scale\_each=False, pad\_value=0) +``make\_grid(tensor, nrow=8, padding=2, normalize=False, range=None, scale\_each=False, pad\_value=0)`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Given a 4D mini-batch Tensor of shape (B x C x H x W), or a list of images all of the same size, makes a grid of images -normalize=True will shift the image to the range (0, 1), +``normalize=True`` will shift the image to the range (0, 1), by subtracting the minimum and dividing by the maximum pixel value. -if range=(min, max) where min and max are numbers, then these numbers are used to +if ``range=(min, max)`` where ``min`` and ``max`` are numbers, then these numbers are used to normalize the image. -scale_each=True will scale each image in the batch of images separately rather than -computing the (min, max) over all images. +``scale_each=True`` will scale each image in the batch of images separately rather than +computing the ``(min, max)`` over all images. -pad_value= sets the value for the padded pixels. +``pad_value=`` sets the value for the padded pixels. `Example usage is given in this notebook` -save\_image(tensor, filename, nrow=8, padding=2, normalize=False, range=None, scale\_each=False, pad\_value=0) +``save\_image(tensor, filename, nrow=8, padding=2, normalize=False, range=None, scale\_each=False, pad\_value=0)`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Saves a given Tensor into an image file. If given a mini-batch tensor, will save the tensor as a grid of images. -All options after `filename` are passed through to `make_grid`. Refer to it's documentation for +All options after ``filename`` are passed through to ``make_grid``. Refer to it's documentation for more details From 3c11a8244b247d0cc7a6effcfc954df3d8867e9f Mon Sep 17 00:00:00 2001 From: Kashif Rasul Date: Sat, 2 Sep 2017 18:50:47 +0200 Subject: [PATCH 4/4] fixed formatting --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 480b3edf6a0..81bd77f1c1b 100644 --- a/README.rst +++ b/README.rst @@ -392,7 +392,7 @@ For example: Utils ===== -``make\_grid(tensor, nrow=8, padding=2, normalize=False, range=None, scale\_each=False, pad\_value=0)`` +``make_grid(tensor, nrow=8, padding=2, normalize=False, range=None, scale_each=False, pad_value=0)`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Given a 4D mini-batch Tensor of shape (B x C x H x W), @@ -412,7 +412,7 @@ computing the ``(min, max)`` over all images. `Example usage is given in this notebook` -``save\_image(tensor, filename, nrow=8, padding=2, normalize=False, range=None, scale\_each=False, pad\_value=0)`` +``save_image(tensor, filename, nrow=8, padding=2, normalize=False, range=None, scale_each=False, pad_value=0)`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Saves a given Tensor into an image file.