Update example for pytorch-fashion-mnist.
"cell_type": "markdown",
"metadata": {},
"source": [
- "## Prepare Dataset\n",
- "\n",
- "Load a custom subclass of torchvision.datasets.MNIST that instead downloads the FashionMNIST dataset \n",
- "\n",
- "(waiting for [this commit](https://github.com/pytorch/vision/commit/eec5ba4405c8815bd1797619d9cc9276f81b76f4) be available in the pip version of PyTorch)."
+ "## Prepare Dataset\n"
]
},
{
"metadata": {},
"outputs": [],
"source": [
- "from torchvision.datasets import MNIST\n",
- "\n",
- "class FashionMNIST(MNIST):\n",
- " \"\"\"`Fashion MNIST <https://github.com/zalandoresearch/fashion-mnist>`_ Dataset.\n",
- " \"\"\"\n",
- " urls = [\n",
- " 'http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-images-idx3-ubyte.gz',\n",
- " 'http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-labels-idx1-ubyte.gz',\n",
- " 'http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-images-idx3-ubyte.gz',\n",
- " 'http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-labels-idx1-ubyte.gz',\n",
- " ]\n",
- "\n",
- " input_shape = (28, 28)\n",
- " num_classes = 10\n",
- "\n",
- " labels = [\n",
- " 'T-shirt/top',\n",
- " 'Trouser',\n",
- " 'Pullover',\n",
- " 'Dress',\n",
- " 'Coat',\n",
- " 'Sandal',\n",
- " 'Shirt',\n",
- " 'Sneaker',\n",
- " 'Bag',\n",
- " 'Ankle boot'\n",
- " ]"
+ "from torchvision.datasets import FashionMNIST"
]
},
{
" encoder, \n",
" nn.Linear(embedding_size, 15),\n",
" nn.ReLU(),\n",
- " nn.Linear(15, len(FashionMNIST.labels)),\n",
+ " nn.Linear(15, len(FashionMNIST.classes)),\n",
" nn.LogSoftmax()\n",
")"
]
"for ax, prob, output_class, target, img in zip(*zip_these):\n",
" ax.imshow(img, cmap='gray' if output_class == target else 'autumn')\n",
" ax.axis('off')\n",
- " ax.set_title('{} {:.1%}'.format(FashionMNIST.labels[output_class], prob))"
+ " ax.set_title('{} {:.1%}'.format(FashionMNIST.classes[output_class], prob))"
]
},
{
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.7.2"
+ "version": "3.7.3"
}
},
"nbformat": 4,
