{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Image Classification Data (Fashion-MNIST)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"ExecuteTime": {
"end_time": "2019-07-03T22:01:31.154647Z",
"start_time": "2019-07-03T22:01:29.325928Z"
},
"attributes": {
"classes": [],
"id": "",
"n": "7"
}
},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import d2l\n",
"from mxnet import gluon \n",
"d2l.use_svg_display()"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"Use the provided `FashionMNIST` class to download and load a dataset. "
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"ExecuteTime": {
"end_time": "2019-07-03T22:01:31.761507Z",
"start_time": "2019-07-03T22:01:31.157805Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"(60000, 10000)"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mnist_train = gluon.data.vision.FashionMNIST(train=True)\n",
"mnist_test = gluon.data.vision.FashionMNIST(train=False)\n",
"\n",
"len(mnist_train), len(mnist_test)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"Visualize the images"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"ExecuteTime": {
"end_time": "2019-07-03T22:01:54.004645Z",
"start_time": "2019-07-03T22:01:53.213167Z"
},
"attributes": {
"classes": [],
"id": "",
"n": "25"
}
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"def get_fashion_mnist_labels(labels):\n",
" text_labels = ['t-shirt', 'trouser', 'pullover', 'dress', 'coat',\n",
" 'sandal', 'shirt', 'sneaker', 'bag', 'ankle boot']\n",
" return [text_labels[int(i)] for i in labels]\n",
"X, y = mnist_train[:18]\n",
"d2l.show_images(X.squeeze(axis=-1), 2, 9, titles=get_fashion_mnist_labels(y));"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"Read a mini-batch"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"ExecuteTime": {
"end_time": "2019-07-03T22:01:32.689503Z",
"start_time": "2019-07-03T22:01:32.582475Z"
},
"attributes": {
"classes": [],
"id": "",
"n": "28"
},
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(256, 1, 28, 28) (256,)\n"
]
}
],
"source": [
"batch_size = 256\n",
"transformer = gluon.data.vision.transforms.ToTensor()\n",
"train_iter = gluon.data.DataLoader(mnist_train.transform_first(transformer),\n",
" batch_size, shuffle=True, num_workers=4)\n",
"\n",
"for X, y in train_iter:\n",
" print(X.shape, y.shape)\n",
" break"
]
}
],
"metadata": {
"celltoolbar": "Slideshow",
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.1"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 2
}