Skip to content

Instantly share code, notes, and snippets.

@devil-cyber
Last active June 21, 2021 07:49
Show Gist options
  • Save devil-cyber/5284c822a34d77207f981b5e91a68d43 to your computer and use it in GitHub Desktop.
Save devil-cyber/5284c822a34d77207f981b5e91a68d43 to your computer and use it in GitHub Desktop.
AlexNet implementation using MXNet
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "AlexNet.ipynb",
"provenance": [],
"authorship_tag": "ABX9TyOQvIXXifvlGA9chzzw87e0",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/devil-cyber/5284c822a34d77207f981b5e91a68d43/alexnet.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"metadata": {
"id": "0H3BD8CENT0k"
},
"source": [
"# !pip install -U mxnet-cu101==1.7.0\n",
"# !pip install mxnet d2l"
],
"execution_count": 6,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "92jxjKO6OKYg"
},
"source": [
"from mxnet import np,npx,init\n",
"from mxnet.gluon import nn\n",
"from d2l import mxnet as d2l\n",
"npx.set_np()"
],
"execution_count": 8,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "Rm7bmqVLOK3e"
},
"source": [
"net = nn.Sequential()"
],
"execution_count": 10,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "g1Ft6TF9OLNn"
},
"source": [
"net.add(\n",
" # Here, we use a larger 11 x 11 window to capture objects. At the same time,\n",
" # we use a stride of 4 to greatly reduce the height and width of the output.\n",
" nn.Conv2D(96,kernel_size=11,strides=4,activation='relu'),\n",
" nn.MaxPool2D(pool_size=3,strides=2),\n",
" # Make the convolution window smaller, set padding to 2 for consistent\n",
" # height and width across the input and output, and increase the\n",
" # number of output channels\n",
" nn.Conv2D(256,kernel_size=5,padding=2,activation='relu'),\n",
" nn.MaxPool2D(pool_size=3,strides=2),\n",
" # Use three successive convolutional layers and a smaller convolution\n",
" # window. Except for the final convolutional layer, the number of\n",
" # output channels is further increased. Pooling layers are not used to\n",
" # reduce the height and width of input after the first two\n",
" # convolutional layers\n",
" nn.Conv2D(384, kernel_size=3,padding=1,activation='relu'),\n",
" nn.Conv2D(384, kernel_size=3,padding=1,activation='relu'),\n",
" nn.Conv2D(256, kernel_size=3,padding=1,activation='relu'),\n",
" nn.MaxPool2D(pool_size=3, strides=2),\n",
" nn.Dense(4096,activation='relu'),\n",
" nn.Dropout(.5),\n",
" nn.Dense(4096,activation='relu'),\n",
" nn.Dropout(0.5),\n",
" nn.Dense(10)\n",
"\n",
")"
],
"execution_count": 16,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "TWkFMOrbOLYf",
"outputId": "1fb84cb4-baa2-4e5c-b584-015b7d223d65"
},
"source": [
"X = np.random.uniform(size=(1,1,224,224))\n",
"net.initialize()\n",
"for layer in net:\n",
" X=layer(X)\n",
" print(layer.name,'output shape:\\t',X.shape)"
],
"execution_count": 17,
"outputs": [
{
"output_type": "stream",
"text": [
"conv2 output shape:\t (1, 96, 54, 54)\n",
"pool1 output shape:\t (1, 96, 26, 26)\n",
"conv3 output shape:\t (1, 256, 26, 26)\n",
"pool2 output shape:\t (1, 256, 12, 12)\n",
"conv4 output shape:\t (1, 384, 12, 12)\n",
"conv5 output shape:\t (1, 384, 12, 12)\n",
"conv6 output shape:\t (1, 256, 12, 12)\n",
"pool3 output shape:\t (1, 256, 5, 5)\n",
"dense0 output shape:\t (1, 4096)\n",
"dropout0 output shape:\t (1, 4096)\n",
"dense1 output shape:\t (1, 4096)\n",
"dropout1 output shape:\t (1, 4096)\n",
"dense2 output shape:\t (1, 10)\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "5aw8vz4_OLiL",
"outputId": "55735940-439a-448d-e688-d3d717394f10"
},
"source": [
"batch_size = 128\n",
"train_iter,test_iter = d2l.load_data_fashion_mnist(batch_size, resize=224)"
],
"execution_count": 18,
"outputs": [
{
"output_type": "stream",
"text": [
"Downloading /root/.mxnet/datasets/fashion-mnist/train-images-idx3-ubyte.gz from https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/fashion-mnist/train-images-idx3-ubyte.gz...\n",
"Downloading /root/.mxnet/datasets/fashion-mnist/train-labels-idx1-ubyte.gz from https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/fashion-mnist/train-labels-idx1-ubyte.gz...\n",
"Downloading /root/.mxnet/datasets/fashion-mnist/t10k-images-idx3-ubyte.gz from https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/fashion-mnist/t10k-images-idx3-ubyte.gz...\n",
"Downloading /root/.mxnet/datasets/fashion-mnist/t10k-labels-idx1-ubyte.gz from https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/fashion-mnist/t10k-labels-idx1-ubyte.gz...\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 296
},
"id": "2--mLBBvRh0e",
"outputId": "091c0f99-e8bb-4f20-d9ee-c6946c9c498c"
},
"source": [
"lr, num_epochs = 0.01,10\n",
"d2l.train_ch6(net,train_iter,test_iter,num_epochs,lr,d2l.try_gpu())"
],
"execution_count": 19,
"outputs": [
{
"output_type": "stream",
"text": [
"loss 0.331, train acc 0.879, test acc 0.890\n",
"1494.6 examples/sec on gpu(0)\n"
],
"name": "stdout"
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"<Figure size 252x180 with 1 Axes>"
],
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Created with matplotlib (https://matplotlib.org/) -->\n<svg height=\"180.65625pt\" version=\"1.1\" viewBox=\"0 0 238.965625 180.65625\" width=\"238.965625pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <defs>\n <style type=\"text/css\">\n*{stroke-linecap:butt;stroke-linejoin:round;}\n </style>\n </defs>\n <g id=\"figure_1\">\n <g id=\"patch_1\">\n <path d=\"M 0 180.65625 \nL 238.965625 180.65625 \nL 238.965625 0 \nL 0 0 \nz\n\" style=\"fill:none;\"/>\n </g>\n <g id=\"axes_1\">\n <g id=\"patch_2\">\n <path d=\"M 30.103125 143.1 \nL 225.403125 143.1 \nL 225.403125 7.2 \nL 30.103125 7.2 \nz\n\" style=\"fill:#ffffff;\"/>\n </g>\n <g id=\"matplotlib.axis_1\">\n <g id=\"xtick_1\">\n <g id=\"line2d_1\">\n <path clip-path=\"url(#pccd5dd1274)\" d=\"M 51.803125 143.1 \nL 51.803125 7.2 \n\" style=\"fill:none;stroke:#b0b0b0;stroke-linecap:square;stroke-width:0.8;\"/>\n </g>\n <g id=\"line2d_2\">\n <defs>\n <path d=\"M 0 0 \nL 0 3.5 \n\" id=\"ma9559e4a7a\" style=\"stroke:#000000;stroke-width:0.8;\"/>\n </defs>\n <g>\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"51.803125\" xlink:href=\"#ma9559e4a7a\" y=\"143.1\"/>\n </g>\n </g>\n <g id=\"text_1\">\n <!-- 2 -->\n <defs>\n <path d=\"M 19.1875 8.296875 \nL 53.609375 8.296875 \nL 53.609375 0 \nL 7.328125 0 \nL 7.328125 8.296875 \nQ 12.9375 14.109375 22.625 23.890625 \nQ 32.328125 33.6875 34.8125 36.53125 \nQ 39.546875 41.84375 41.421875 45.53125 \nQ 43.3125 49.21875 43.3125 52.78125 \nQ 43.3125 58.59375 39.234375 62.25 \nQ 35.15625 65.921875 28.609375 65.921875 \nQ 23.96875 65.921875 18.8125 64.3125 \nQ 13.671875 62.703125 7.8125 59.421875 \nL 7.8125 69.390625 \nQ 13.765625 71.78125 18.9375 73 \nQ 24.125 74.21875 28.421875 74.21875 \nQ 39.75 74.21875 46.484375 68.546875 \nQ 53.21875 62.890625 53.21875 53.421875 \nQ 53.21875 48.921875 51.53125 44.890625 \nQ 49.859375 40.875 45.40625 35.40625 \nQ 44.1875 33.984375 37.640625 27.21875 \nQ 31.109375 20.453125 19.1875 8.296875 \nz\n\" id=\"DejaVuSans-50\"/>\n </defs>\n <g transform=\"translate(48.621875 157.698438)scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-50\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_2\">\n <g id=\"line2d_3\">\n <path clip-path=\"url(#pccd5dd1274)\" d=\"M 95.203125 143.1 \nL 95.203125 7.2 \n\" style=\"fill:none;stroke:#b0b0b0;stroke-linecap:square;stroke-width:0.8;\"/>\n </g>\n <g id=\"line2d_4\">\n <g>\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"95.203125\" xlink:href=\"#ma9559e4a7a\" y=\"143.1\"/>\n </g>\n </g>\n <g id=\"text_2\">\n <!-- 4 -->\n <defs>\n <path d=\"M 37.796875 64.3125 \nL 12.890625 25.390625 \nL 37.796875 25.390625 \nz\nM 35.203125 72.90625 \nL 47.609375 72.90625 \nL 47.609375 25.390625 \nL 58.015625 25.390625 \nL 58.015625 17.1875 \nL 47.609375 17.1875 \nL 47.609375 0 \nL 37.796875 0 \nL 37.796875 17.1875 \nL 4.890625 17.1875 \nL 4.890625 26.703125 \nz\n\" id=\"DejaVuSans-52\"/>\n </defs>\n <g transform=\"translate(92.021875 157.698438)scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-52\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_3\">\n <g id=\"line2d_5\">\n <path clip-path=\"url(#pccd5dd1274)\" d=\"M 138.603125 143.1 \nL 138.603125 7.2 \n\" style=\"fill:none;stroke:#b0b0b0;stroke-linecap:square;stroke-width:0.8;\"/>\n </g>\n <g id=\"line2d_6\">\n <g>\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"138.603125\" xlink:href=\"#ma9559e4a7a\" y=\"143.1\"/>\n </g>\n </g>\n <g id=\"text_3\">\n <!-- 6 -->\n <defs>\n <path d=\"M 33.015625 40.375 \nQ 26.375 40.375 22.484375 35.828125 \nQ 18.609375 31.296875 18.609375 23.390625 \nQ 18.609375 15.53125 22.484375 10.953125 \nQ 26.375 6.390625 33.015625 6.390625 \nQ 39.65625 6.390625 43.53125 10.953125 \nQ 47.40625 15.53125 47.40625 23.390625 \nQ 47.40625 31.296875 43.53125 35.828125 \nQ 39.65625 40.375 33.015625 40.375 \nz\nM 52.59375 71.296875 \nL 52.59375 62.3125 \nQ 48.875 64.0625 45.09375 64.984375 \nQ 41.3125 65.921875 37.59375 65.921875 \nQ 27.828125 65.921875 22.671875 59.328125 \nQ 17.53125 52.734375 16.796875 39.40625 \nQ 19.671875 43.65625 24.015625 45.921875 \nQ 28.375 48.1875 33.59375 48.1875 \nQ 44.578125 48.1875 50.953125 41.515625 \nQ 57.328125 34.859375 57.328125 23.390625 \nQ 57.328125 12.15625 50.6875 5.359375 \nQ 44.046875 -1.421875 33.015625 -1.421875 \nQ 20.359375 -1.421875 13.671875 8.265625 \nQ 6.984375 17.96875 6.984375 36.375 \nQ 6.984375 53.65625 15.1875 63.9375 \nQ 23.390625 74.21875 37.203125 74.21875 \nQ 40.921875 74.21875 44.703125 73.484375 \nQ 48.484375 72.75 52.59375 71.296875 \nz\n\" id=\"DejaVuSans-54\"/>\n </defs>\n <g transform=\"translate(135.421875 157.698438)scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-54\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_4\">\n <g id=\"line2d_7\">\n <path clip-path=\"url(#pccd5dd1274)\" d=\"M 182.003125 143.1 \nL 182.003125 7.2 \n\" style=\"fill:none;stroke:#b0b0b0;stroke-linecap:square;stroke-width:0.8;\"/>\n </g>\n <g id=\"line2d_8\">\n <g>\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"182.003125\" xlink:href=\"#ma9559e4a7a\" y=\"143.1\"/>\n </g>\n </g>\n <g id=\"text_4\">\n <!-- 8 -->\n <defs>\n <path d=\"M 31.78125 34.625 \nQ 24.75 34.625 20.71875 30.859375 \nQ 16.703125 27.09375 16.703125 20.515625 \nQ 16.703125 13.921875 20.71875 10.15625 \nQ 24.75 6.390625 31.78125 6.390625 \nQ 38.8125 6.390625 42.859375 10.171875 \nQ 46.921875 13.96875 46.921875 20.515625 \nQ 46.921875 27.09375 42.890625 30.859375 \nQ 38.875 34.625 31.78125 34.625 \nz\nM 21.921875 38.8125 \nQ 15.578125 40.375 12.03125 44.71875 \nQ 8.5 49.078125 8.5 55.328125 \nQ 8.5 64.0625 14.71875 69.140625 \nQ 20.953125 74.21875 31.78125 74.21875 \nQ 42.671875 74.21875 48.875 69.140625 \nQ 55.078125 64.0625 55.078125 55.328125 \nQ 55.078125 49.078125 51.53125 44.71875 \nQ 48 40.375 41.703125 38.8125 \nQ 48.828125 37.15625 52.796875 32.3125 \nQ 56.78125 27.484375 56.78125 20.515625 \nQ 56.78125 9.90625 50.3125 4.234375 \nQ 43.84375 -1.421875 31.78125 -1.421875 \nQ 19.734375 -1.421875 13.25 4.234375 \nQ 6.78125 9.90625 6.78125 20.515625 \nQ 6.78125 27.484375 10.78125 32.3125 \nQ 14.796875 37.15625 21.921875 38.8125 \nz\nM 18.3125 54.390625 \nQ 18.3125 48.734375 21.84375 45.5625 \nQ 25.390625 42.390625 31.78125 42.390625 \nQ 38.140625 42.390625 41.71875 45.5625 \nQ 45.3125 48.734375 45.3125 54.390625 \nQ 45.3125 60.0625 41.71875 63.234375 \nQ 38.140625 66.40625 31.78125 66.40625 \nQ 25.390625 66.40625 21.84375 63.234375 \nQ 18.3125 60.0625 18.3125 54.390625 \nz\n\" id=\"DejaVuSans-56\"/>\n </defs>\n <g transform=\"translate(178.821875 157.698438)scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-56\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_5\">\n <g id=\"line2d_9\">\n <path clip-path=\"url(#pccd5dd1274)\" d=\"M 225.403125 143.1 \nL 225.403125 7.2 \n\" style=\"fill:none;stroke:#b0b0b0;stroke-linecap:square;stroke-width:0.8;\"/>\n </g>\n <g id=\"line2d_10\">\n <g>\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"225.403125\" xlink:href=\"#ma9559e4a7a\" y=\"143.1\"/>\n </g>\n </g>\n <g id=\"text_5\">\n <!-- 10 -->\n <defs>\n <path d=\"M 12.40625 8.296875 \nL 28.515625 8.296875 \nL 28.515625 63.921875 \nL 10.984375 60.40625 \nL 10.984375 69.390625 \nL 28.421875 72.90625 \nL 38.28125 72.90625 \nL 38.28125 8.296875 \nL 54.390625 8.296875 \nL 54.390625 0 \nL 12.40625 0 \nz\n\" id=\"DejaVuSans-49\"/>\n <path d=\"M 31.78125 66.40625 \nQ 24.171875 66.40625 20.328125 58.90625 \nQ 16.5 51.421875 16.5 36.375 \nQ 16.5 21.390625 20.328125 13.890625 \nQ 24.171875 6.390625 31.78125 6.390625 \nQ 39.453125 6.390625 43.28125 13.890625 \nQ 47.125 21.390625 47.125 36.375 \nQ 47.125 51.421875 43.28125 58.90625 \nQ 39.453125 66.40625 31.78125 66.40625 \nz\nM 31.78125 74.21875 \nQ 44.046875 74.21875 50.515625 64.515625 \nQ 56.984375 54.828125 56.984375 36.375 \nQ 56.984375 17.96875 50.515625 8.265625 \nQ 44.046875 -1.421875 31.78125 -1.421875 \nQ 19.53125 -1.421875 13.0625 8.265625 \nQ 6.59375 17.96875 6.59375 36.375 \nQ 6.59375 54.828125 13.0625 64.515625 \nQ 19.53125 74.21875 31.78125 74.21875 \nz\n\" id=\"DejaVuSans-48\"/>\n </defs>\n <g transform=\"translate(219.040625 157.698438)scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-49\"/>\n <use x=\"63.623047\" xlink:href=\"#DejaVuSans-48\"/>\n </g>\n </g>\n </g>\n <g id=\"text_6\">\n <!-- epoch -->\n <defs>\n <path d=\"M 56.203125 29.59375 \nL 56.203125 25.203125 \nL 14.890625 25.203125 \nQ 15.484375 15.921875 20.484375 11.0625 \nQ 25.484375 6.203125 34.421875 6.203125 \nQ 39.59375 6.203125 44.453125 7.46875 \nQ 49.3125 8.734375 54.109375 11.28125 \nL 54.109375 2.78125 \nQ 49.265625 0.734375 44.1875 -0.34375 \nQ 39.109375 -1.421875 33.890625 -1.421875 \nQ 20.796875 -1.421875 13.15625 6.1875 \nQ 5.515625 13.8125 5.515625 26.8125 \nQ 5.515625 40.234375 12.765625 48.109375 \nQ 20.015625 56 32.328125 56 \nQ 43.359375 56 49.78125 48.890625 \nQ 56.203125 41.796875 56.203125 29.59375 \nz\nM 47.21875 32.234375 \nQ 47.125 39.59375 43.09375 43.984375 \nQ 39.0625 48.390625 32.421875 48.390625 \nQ 24.90625 48.390625 20.390625 44.140625 \nQ 15.875 39.890625 15.1875 32.171875 \nz\n\" id=\"DejaVuSans-101\"/>\n <path d=\"M 18.109375 8.203125 \nL 18.109375 -20.796875 \nL 9.078125 -20.796875 \nL 9.078125 54.6875 \nL 18.109375 54.6875 \nL 18.109375 46.390625 \nQ 20.953125 51.265625 25.265625 53.625 \nQ 29.59375 56 35.59375 56 \nQ 45.5625 56 51.78125 48.09375 \nQ 58.015625 40.1875 58.015625 27.296875 \nQ 58.015625 14.40625 51.78125 6.484375 \nQ 45.5625 -1.421875 35.59375 -1.421875 \nQ 29.59375 -1.421875 25.265625 0.953125 \nQ 20.953125 3.328125 18.109375 8.203125 \nz\nM 48.6875 27.296875 \nQ 48.6875 37.203125 44.609375 42.84375 \nQ 40.53125 48.484375 33.40625 48.484375 \nQ 26.265625 48.484375 22.1875 42.84375 \nQ 18.109375 37.203125 18.109375 27.296875 \nQ 18.109375 17.390625 22.1875 11.75 \nQ 26.265625 6.109375 33.40625 6.109375 \nQ 40.53125 6.109375 44.609375 11.75 \nQ 48.6875 17.390625 48.6875 27.296875 \nz\n\" id=\"DejaVuSans-112\"/>\n <path d=\"M 30.609375 48.390625 \nQ 23.390625 48.390625 19.1875 42.75 \nQ 14.984375 37.109375 14.984375 27.296875 \nQ 14.984375 17.484375 19.15625 11.84375 \nQ 23.34375 6.203125 30.609375 6.203125 \nQ 37.796875 6.203125 41.984375 11.859375 \nQ 46.1875 17.53125 46.1875 27.296875 \nQ 46.1875 37.015625 41.984375 42.703125 \nQ 37.796875 48.390625 30.609375 48.390625 \nz\nM 30.609375 56 \nQ 42.328125 56 49.015625 48.375 \nQ 55.71875 40.765625 55.71875 27.296875 \nQ 55.71875 13.875 49.015625 6.21875 \nQ 42.328125 -1.421875 30.609375 -1.421875 \nQ 18.84375 -1.421875 12.171875 6.21875 \nQ 5.515625 13.875 5.515625 27.296875 \nQ 5.515625 40.765625 12.171875 48.375 \nQ 18.84375 56 30.609375 56 \nz\n\" id=\"DejaVuSans-111\"/>\n <path d=\"M 48.78125 52.59375 \nL 48.78125 44.1875 \nQ 44.96875 46.296875 41.140625 47.34375 \nQ 37.3125 48.390625 33.40625 48.390625 \nQ 24.65625 48.390625 19.8125 42.84375 \nQ 14.984375 37.3125 14.984375 27.296875 \nQ 14.984375 17.28125 19.8125 11.734375 \nQ 24.65625 6.203125 33.40625 6.203125 \nQ 37.3125 6.203125 41.140625 7.25 \nQ 44.96875 8.296875 48.78125 10.40625 \nL 48.78125 2.09375 \nQ 45.015625 0.34375 40.984375 -0.53125 \nQ 36.96875 -1.421875 32.421875 -1.421875 \nQ 20.0625 -1.421875 12.78125 6.34375 \nQ 5.515625 14.109375 5.515625 27.296875 \nQ 5.515625 40.671875 12.859375 48.328125 \nQ 20.21875 56 33.015625 56 \nQ 37.15625 56 41.109375 55.140625 \nQ 45.0625 54.296875 48.78125 52.59375 \nz\n\" id=\"DejaVuSans-99\"/>\n <path d=\"M 54.890625 33.015625 \nL 54.890625 0 \nL 45.90625 0 \nL 45.90625 32.71875 \nQ 45.90625 40.484375 42.875 44.328125 \nQ 39.84375 48.1875 33.796875 48.1875 \nQ 26.515625 48.1875 22.3125 43.546875 \nQ 18.109375 38.921875 18.109375 30.90625 \nL 18.109375 0 \nL 9.078125 0 \nL 9.078125 75.984375 \nL 18.109375 75.984375 \nL 18.109375 46.1875 \nQ 21.34375 51.125 25.703125 53.5625 \nQ 30.078125 56 35.796875 56 \nQ 45.21875 56 50.046875 50.171875 \nQ 54.890625 44.34375 54.890625 33.015625 \nz\n\" id=\"DejaVuSans-104\"/>\n </defs>\n <g transform=\"translate(112.525 171.376563)scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-101\"/>\n <use x=\"61.523438\" xlink:href=\"#DejaVuSans-112\"/>\n <use x=\"125\" xlink:href=\"#DejaVuSans-111\"/>\n <use x=\"186.181641\" xlink:href=\"#DejaVuSans-99\"/>\n <use x=\"241.162109\" xlink:href=\"#DejaVuSans-104\"/>\n </g>\n </g>\n </g>\n <g id=\"matplotlib.axis_2\">\n <g id=\"ytick_1\">\n <g id=\"line2d_11\">\n <path clip-path=\"url(#pccd5dd1274)\" d=\"M 30.103125 117.735026 \nL 225.403125 117.735026 \n\" style=\"fill:none;stroke:#b0b0b0;stroke-linecap:square;stroke-width:0.8;\"/>\n </g>\n <g id=\"line2d_12\">\n <defs>\n <path d=\"M 0 0 \nL -3.5 0 \n\" id=\"m0b99603ca1\" style=\"stroke:#000000;stroke-width:0.8;\"/>\n </defs>\n <g>\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"30.103125\" xlink:href=\"#m0b99603ca1\" y=\"117.735026\"/>\n </g>\n </g>\n <g id=\"text_7\">\n <!-- 0.5 -->\n <defs>\n <path d=\"M 10.6875 12.40625 \nL 21 12.40625 \nL 21 0 \nL 10.6875 0 \nz\n\" id=\"DejaVuSans-46\"/>\n <path d=\"M 10.796875 72.90625 \nL 49.515625 72.90625 \nL 49.515625 64.59375 \nL 19.828125 64.59375 \nL 19.828125 46.734375 \nQ 21.96875 47.46875 24.109375 47.828125 \nQ 26.265625 48.1875 28.421875 48.1875 \nQ 40.625 48.1875 47.75 41.5 \nQ 54.890625 34.8125 54.890625 23.390625 \nQ 54.890625 11.625 47.5625 5.09375 \nQ 40.234375 -1.421875 26.90625 -1.421875 \nQ 22.3125 -1.421875 17.546875 -0.640625 \nQ 12.796875 0.140625 7.71875 1.703125 \nL 7.71875 11.625 \nQ 12.109375 9.234375 16.796875 8.0625 \nQ 21.484375 6.890625 26.703125 6.890625 \nQ 35.15625 6.890625 40.078125 11.328125 \nQ 45.015625 15.765625 45.015625 23.390625 \nQ 45.015625 31 40.078125 35.4375 \nQ 35.15625 39.890625 26.703125 39.890625 \nQ 22.75 39.890625 18.8125 39.015625 \nQ 14.890625 38.140625 10.796875 36.28125 \nz\n\" id=\"DejaVuSans-53\"/>\n </defs>\n <g transform=\"translate(7.2 121.534244)scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-48\"/>\n <use x=\"63.623047\" xlink:href=\"#DejaVuSans-46\"/>\n <use x=\"95.410156\" xlink:href=\"#DejaVuSans-53\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_2\">\n <g id=\"line2d_13\">\n <path clip-path=\"url(#pccd5dd1274)\" d=\"M 30.103125 88.511586 \nL 225.403125 88.511586 \n\" style=\"fill:none;stroke:#b0b0b0;stroke-linecap:square;stroke-width:0.8;\"/>\n </g>\n <g id=\"line2d_14\">\n <g>\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"30.103125\" xlink:href=\"#m0b99603ca1\" y=\"88.511586\"/>\n </g>\n </g>\n <g id=\"text_8\">\n <!-- 1.0 -->\n <g transform=\"translate(7.2 92.310805)scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-49\"/>\n <use x=\"63.623047\" xlink:href=\"#DejaVuSans-46\"/>\n <use x=\"95.410156\" xlink:href=\"#DejaVuSans-48\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_3\">\n <g id=\"line2d_15\">\n <path clip-path=\"url(#pccd5dd1274)\" d=\"M 30.103125 59.288147 \nL 225.403125 59.288147 \n\" style=\"fill:none;stroke:#b0b0b0;stroke-linecap:square;stroke-width:0.8;\"/>\n </g>\n <g id=\"line2d_16\">\n <g>\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"30.103125\" xlink:href=\"#m0b99603ca1\" y=\"59.288147\"/>\n </g>\n </g>\n <g id=\"text_9\">\n <!-- 1.5 -->\n <g transform=\"translate(7.2 63.087366)scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-49\"/>\n <use x=\"63.623047\" xlink:href=\"#DejaVuSans-46\"/>\n <use x=\"95.410156\" xlink:href=\"#DejaVuSans-53\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_4\">\n <g id=\"line2d_17\">\n <path clip-path=\"url(#pccd5dd1274)\" d=\"M 30.103125 30.064708 \nL 225.403125 30.064708 \n\" style=\"fill:none;stroke:#b0b0b0;stroke-linecap:square;stroke-width:0.8;\"/>\n </g>\n <g id=\"line2d_18\">\n <g>\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"30.103125\" xlink:href=\"#m0b99603ca1\" y=\"30.064708\"/>\n </g>\n </g>\n <g id=\"text_10\">\n <!-- 2.0 -->\n <g transform=\"translate(7.2 33.863927)scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-50\"/>\n <use x=\"63.623047\" xlink:href=\"#DejaVuSans-46\"/>\n <use x=\"95.410156\" xlink:href=\"#DejaVuSans-48\"/>\n </g>\n </g>\n </g>\n </g>\n <g id=\"line2d_19\">\n <path clip-path=\"url(#pccd5dd1274)\" d=\"M 12.70611 13.377273 \nL 17.009095 31.143638 \nL 21.31208 49.130312 \nL 25.615065 60.448377 \nL 29.91805 68.373981 \nL 30.103125 68.680283 \nL 34.40611 103.01356 \nL 38.709095 104.547186 \nL 43.01208 105.976024 \nL 47.315065 107.075192 \nL 51.61805 107.981739 \nL 51.803125 108.000477 \nL 56.10611 113.80585 \nL 60.409095 114.010996 \nL 64.71208 114.204756 \nL 69.015065 114.701662 \nL 73.31805 115.08902 \nL 73.503125 115.109172 \nL 77.80611 118.099292 \nL 82.109095 118.018451 \nL 86.41208 118.355401 \nL 90.715065 118.654261 \nL 95.01805 119.007047 \nL 95.203125 119.035433 \nL 99.50611 120.753258 \nL 103.809095 120.68994 \nL 108.11208 120.919702 \nL 112.415065 121.168693 \nL 116.71805 121.563604 \nL 116.903125 121.559169 \nL 121.20611 122.779419 \nL 125.509095 123.23854 \nL 129.81208 123.20432 \nL 134.115065 123.173161 \nL 138.41805 123.381573 \nL 138.603125 123.422766 \nL 142.90611 124.788097 \nL 147.209095 124.640157 \nL 151.51208 124.92294 \nL 155.815065 124.691606 \nL 160.11805 124.730481 \nL 160.303125 124.741989 \nL 164.60611 125.592054 \nL 168.909095 125.692515 \nL 173.21208 125.927662 \nL 177.515065 125.748365 \nL 181.81805 125.817965 \nL 182.003125 125.808924 \nL 186.30611 125.932492 \nL 190.609095 126.045547 \nL 194.91208 126.386769 \nL 199.215065 126.547978 \nL 203.51805 126.706688 \nL 203.703125 126.697947 \nL 208.00611 127.847777 \nL 212.309095 127.76228 \nL 216.61208 127.64811 \nL 220.915065 127.583377 \nL 225.21805 127.601447 \nL 225.403125 127.610634 \n\" style=\"fill:none;stroke:#1f77b4;stroke-linecap:square;stroke-width:1.5;\"/>\n </g>\n <g id=\"line2d_20\">\n <path clip-path=\"url(#pccd5dd1274)\" d=\"M 12.70611 136.922727 \nL 17.009095 130.611112 \nL 21.31208 124.435337 \nL 25.615065 120.498045 \nL 29.91805 117.613261 \nL 30.103125 117.500264 \nL 34.40611 105.057788 \nL 38.709095 104.426872 \nL 43.01208 103.835234 \nL 47.315065 103.426489 \nL 51.61805 103.088937 \nL 51.803125 103.080445 \nL 56.10611 100.913873 \nL 60.409095 100.830405 \nL 64.71208 100.696202 \nL 69.015065 100.473213 \nL 73.31805 100.341384 \nL 73.503125 100.329545 \nL 77.80611 99.102137 \nL 82.109095 99.082498 \nL 86.41208 99.023579 \nL 90.715065 98.960979 \nL 95.01805 98.834059 \nL 95.203125 98.823564 \nL 99.50611 98.277282 \nL 103.809095 98.122622 \nL 108.11208 97.989237 \nL 112.415065 97.918863 \nL 116.71805 97.81772 \nL 116.903125 97.822174 \nL 121.20611 97.221664 \nL 125.509095 97.094008 \nL 129.81208 97.110374 \nL 134.115065 97.151698 \nL 138.41805 97.074368 \nL 138.603125 97.058468 \nL 142.90611 96.612842 \nL 147.209095 96.612842 \nL 151.51208 96.576837 \nL 155.815065 96.625117 \nL 160.11805 96.609896 \nL 160.303125 96.605505 \nL 164.60611 96.382079 \nL 168.909095 96.298612 \nL 173.21208 96.216781 \nL 177.515065 96.271607 \nL 181.81805 96.236747 \nL 182.003125 96.239238 \nL 186.30611 96.244603 \nL 190.609095 96.220054 \nL 194.91208 96.059665 \nL 199.215065 95.958604 \nL 203.51805 95.89404 \nL 203.703125 95.899272 \nL 208.00611 95.527765 \nL 212.309095 95.471302 \nL 216.61208 95.57359 \nL 220.915065 95.616142 \nL 225.21805 95.580791 \nL 225.403125 95.57684 \n\" style=\"fill:none;stroke:#bf00bf;stroke-dasharray:5.55,2.4;stroke-dashoffset:0;stroke-width:1.5;\"/>\n </g>\n <g id=\"line2d_21\">\n <path clip-path=\"url(#pccd5dd1274)\" d=\"M 30.103125 104.204573 \nL 51.803125 99.984709 \nL 73.503125 98.757324 \nL 95.203125 97.091588 \nL 116.903125 96.735062 \nL 138.603125 95.881738 \nL 160.303125 95.782378 \nL 182.003125 95.636261 \nL 203.703125 95.466765 \nL 225.403125 94.940743 \n\" style=\"fill:none;stroke:#008000;stroke-dasharray:9.6,2.4,1.5,2.4;stroke-dashoffset:0;stroke-width:1.5;\"/>\n </g>\n <g id=\"patch_3\">\n <path d=\"M 30.103125 143.1 \nL 30.103125 7.2 \n\" style=\"fill:none;stroke:#000000;stroke-linecap:square;stroke-linejoin:miter;stroke-width:0.8;\"/>\n </g>\n <g id=\"patch_4\">\n <path d=\"M 225.403125 143.1 \nL 225.403125 7.2 \n\" style=\"fill:none;stroke:#000000;stroke-linecap:square;stroke-linejoin:miter;stroke-width:0.8;\"/>\n </g>\n <g id=\"patch_5\">\n <path d=\"M 30.103125 143.1 \nL 225.403125 143.1 \n\" style=\"fill:none;stroke:#000000;stroke-linecap:square;stroke-linejoin:miter;stroke-width:0.8;\"/>\n </g>\n <g id=\"patch_6\">\n <path d=\"M 30.103125 7.2 \nL 225.403125 7.2 \n\" style=\"fill:none;stroke:#000000;stroke-linecap:square;stroke-linejoin:miter;stroke-width:0.8;\"/>\n </g>\n <g id=\"legend_1\">\n <g id=\"patch_7\">\n <path d=\"M 140.634375 59.234375 \nL 218.403125 59.234375 \nQ 220.403125 59.234375 220.403125 57.234375 \nL 220.403125 14.2 \nQ 220.403125 12.2 218.403125 12.2 \nL 140.634375 12.2 \nQ 138.634375 12.2 138.634375 14.2 \nL 138.634375 57.234375 \nQ 138.634375 59.234375 140.634375 59.234375 \nz\n\" style=\"fill:#ffffff;opacity:0.8;stroke:#cccccc;stroke-linejoin:miter;\"/>\n </g>\n <g id=\"line2d_22\">\n <path d=\"M 142.634375 20.298438 \nL 162.634375 20.298438 \n\" style=\"fill:none;stroke:#1f77b4;stroke-linecap:square;stroke-width:1.5;\"/>\n </g>\n <g id=\"line2d_23\"/>\n <g id=\"text_11\">\n <!-- train loss -->\n <defs>\n <path d=\"M 18.3125 70.21875 \nL 18.3125 54.6875 \nL 36.8125 54.6875 \nL 36.8125 47.703125 \nL 18.3125 47.703125 \nL 18.3125 18.015625 \nQ 18.3125 11.328125 20.140625 9.421875 \nQ 21.96875 7.515625 27.59375 7.515625 \nL 36.8125 7.515625 \nL 36.8125 0 \nL 27.59375 0 \nQ 17.1875 0 13.234375 3.875 \nQ 9.28125 7.765625 9.28125 18.015625 \nL 9.28125 47.703125 \nL 2.6875 47.703125 \nL 2.6875 54.6875 \nL 9.28125 54.6875 \nL 9.28125 70.21875 \nz\n\" id=\"DejaVuSans-116\"/>\n <path d=\"M 41.109375 46.296875 \nQ 39.59375 47.171875 37.8125 47.578125 \nQ 36.03125 48 33.890625 48 \nQ 26.265625 48 22.1875 43.046875 \nQ 18.109375 38.09375 18.109375 28.8125 \nL 18.109375 0 \nL 9.078125 0 \nL 9.078125 54.6875 \nL 18.109375 54.6875 \nL 18.109375 46.1875 \nQ 20.953125 51.171875 25.484375 53.578125 \nQ 30.03125 56 36.53125 56 \nQ 37.453125 56 38.578125 55.875 \nQ 39.703125 55.765625 41.0625 55.515625 \nz\n\" id=\"DejaVuSans-114\"/>\n <path d=\"M 34.28125 27.484375 \nQ 23.390625 27.484375 19.1875 25 \nQ 14.984375 22.515625 14.984375 16.5 \nQ 14.984375 11.71875 18.140625 8.90625 \nQ 21.296875 6.109375 26.703125 6.109375 \nQ 34.1875 6.109375 38.703125 11.40625 \nQ 43.21875 16.703125 43.21875 25.484375 \nL 43.21875 27.484375 \nz\nM 52.203125 31.203125 \nL 52.203125 0 \nL 43.21875 0 \nL 43.21875 8.296875 \nQ 40.140625 3.328125 35.546875 0.953125 \nQ 30.953125 -1.421875 24.3125 -1.421875 \nQ 15.921875 -1.421875 10.953125 3.296875 \nQ 6 8.015625 6 15.921875 \nQ 6 25.140625 12.171875 29.828125 \nQ 18.359375 34.515625 30.609375 34.515625 \nL 43.21875 34.515625 \nL 43.21875 35.40625 \nQ 43.21875 41.609375 39.140625 45 \nQ 35.0625 48.390625 27.6875 48.390625 \nQ 23 48.390625 18.546875 47.265625 \nQ 14.109375 46.140625 10.015625 43.890625 \nL 10.015625 52.203125 \nQ 14.9375 54.109375 19.578125 55.046875 \nQ 24.21875 56 28.609375 56 \nQ 40.484375 56 46.34375 49.84375 \nQ 52.203125 43.703125 52.203125 31.203125 \nz\n\" id=\"DejaVuSans-97\"/>\n <path d=\"M 9.421875 54.6875 \nL 18.40625 54.6875 \nL 18.40625 0 \nL 9.421875 0 \nz\nM 9.421875 75.984375 \nL 18.40625 75.984375 \nL 18.40625 64.59375 \nL 9.421875 64.59375 \nz\n\" id=\"DejaVuSans-105\"/>\n <path d=\"M 54.890625 33.015625 \nL 54.890625 0 \nL 45.90625 0 \nL 45.90625 32.71875 \nQ 45.90625 40.484375 42.875 44.328125 \nQ 39.84375 48.1875 33.796875 48.1875 \nQ 26.515625 48.1875 22.3125 43.546875 \nQ 18.109375 38.921875 18.109375 30.90625 \nL 18.109375 0 \nL 9.078125 0 \nL 9.078125 54.6875 \nL 18.109375 54.6875 \nL 18.109375 46.1875 \nQ 21.34375 51.125 25.703125 53.5625 \nQ 30.078125 56 35.796875 56 \nQ 45.21875 56 50.046875 50.171875 \nQ 54.890625 44.34375 54.890625 33.015625 \nz\n\" id=\"DejaVuSans-110\"/>\n <path id=\"DejaVuSans-32\"/>\n <path d=\"M 9.421875 75.984375 \nL 18.40625 75.984375 \nL 18.40625 0 \nL 9.421875 0 \nz\n\" id=\"DejaVuSans-108\"/>\n <path d=\"M 44.28125 53.078125 \nL 44.28125 44.578125 \nQ 40.484375 46.53125 36.375 47.5 \nQ 32.28125 48.484375 27.875 48.484375 \nQ 21.1875 48.484375 17.84375 46.4375 \nQ 14.5 44.390625 14.5 40.28125 \nQ 14.5 37.15625 16.890625 35.375 \nQ 19.28125 33.59375 26.515625 31.984375 \nL 29.59375 31.296875 \nQ 39.15625 29.25 43.1875 25.515625 \nQ 47.21875 21.78125 47.21875 15.09375 \nQ 47.21875 7.46875 41.1875 3.015625 \nQ 35.15625 -1.421875 24.609375 -1.421875 \nQ 20.21875 -1.421875 15.453125 -0.5625 \nQ 10.6875 0.296875 5.421875 2 \nL 5.421875 11.28125 \nQ 10.40625 8.6875 15.234375 7.390625 \nQ 20.0625 6.109375 24.8125 6.109375 \nQ 31.15625 6.109375 34.5625 8.28125 \nQ 37.984375 10.453125 37.984375 14.40625 \nQ 37.984375 18.0625 35.515625 20.015625 \nQ 33.0625 21.96875 24.703125 23.78125 \nL 21.578125 24.515625 \nQ 13.234375 26.265625 9.515625 29.90625 \nQ 5.8125 33.546875 5.8125 39.890625 \nQ 5.8125 47.609375 11.28125 51.796875 \nQ 16.75 56 26.8125 56 \nQ 31.78125 56 36.171875 55.265625 \nQ 40.578125 54.546875 44.28125 53.078125 \nz\n\" id=\"DejaVuSans-115\"/>\n </defs>\n <g transform=\"translate(170.634375 23.798438)scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-116\"/>\n <use x=\"39.208984\" xlink:href=\"#DejaVuSans-114\"/>\n <use x=\"80.322266\" xlink:href=\"#DejaVuSans-97\"/>\n <use x=\"141.601562\" xlink:href=\"#DejaVuSans-105\"/>\n <use x=\"169.384766\" xlink:href=\"#DejaVuSans-110\"/>\n <use x=\"232.763672\" xlink:href=\"#DejaVuSans-32\"/>\n <use x=\"264.550781\" xlink:href=\"#DejaVuSans-108\"/>\n <use x=\"292.333984\" xlink:href=\"#DejaVuSans-111\"/>\n <use x=\"353.515625\" xlink:href=\"#DejaVuSans-115\"/>\n <use x=\"405.615234\" xlink:href=\"#DejaVuSans-115\"/>\n </g>\n </g>\n <g id=\"line2d_24\">\n <path d=\"M 142.634375 34.976562 \nL 162.634375 34.976562 \n\" style=\"fill:none;stroke:#bf00bf;stroke-dasharray:5.55,2.4;stroke-dashoffset:0;stroke-width:1.5;\"/>\n </g>\n <g id=\"line2d_25\"/>\n <g id=\"text_12\">\n <!-- train acc -->\n <g transform=\"translate(170.634375 38.476562)scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-116\"/>\n <use x=\"39.208984\" xlink:href=\"#DejaVuSans-114\"/>\n <use x=\"80.322266\" xlink:href=\"#DejaVuSans-97\"/>\n <use x=\"141.601562\" xlink:href=\"#DejaVuSans-105\"/>\n <use x=\"169.384766\" xlink:href=\"#DejaVuSans-110\"/>\n <use x=\"232.763672\" xlink:href=\"#DejaVuSans-32\"/>\n <use x=\"264.550781\" xlink:href=\"#DejaVuSans-97\"/>\n <use x=\"325.830078\" xlink:href=\"#DejaVuSans-99\"/>\n <use x=\"380.810547\" xlink:href=\"#DejaVuSans-99\"/>\n </g>\n </g>\n <g id=\"line2d_26\">\n <path d=\"M 142.634375 49.654688 \nL 162.634375 49.654688 \n\" style=\"fill:none;stroke:#008000;stroke-dasharray:9.6,2.4,1.5,2.4;stroke-dashoffset:0;stroke-width:1.5;\"/>\n </g>\n <g id=\"line2d_27\"/>\n <g id=\"text_13\">\n <!-- test acc -->\n <g transform=\"translate(170.634375 53.154688)scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-116\"/>\n <use x=\"39.208984\" xlink:href=\"#DejaVuSans-101\"/>\n <use x=\"100.732422\" xlink:href=\"#DejaVuSans-115\"/>\n <use x=\"152.832031\" xlink:href=\"#DejaVuSans-116\"/>\n <use x=\"192.041016\" xlink:href=\"#DejaVuSans-32\"/>\n <use x=\"223.828125\" xlink:href=\"#DejaVuSans-97\"/>\n <use x=\"285.107422\" xlink:href=\"#DejaVuSans-99\"/>\n <use x=\"340.087891\" xlink:href=\"#DejaVuSans-99\"/>\n </g>\n </g>\n </g>\n </g>\n </g>\n <defs>\n <clipPath id=\"pccd5dd1274\">\n <rect height=\"135.9\" width=\"195.3\" x=\"30.103125\" y=\"7.2\"/>\n </clipPath>\n </defs>\n</svg>\n"
},
"metadata": {
"tags": [],
"needs_background": "light"
}
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "4oCbbFh0T1PG"
},
"source": [
"# Data for prediction\n",
"for X,y in test_iter:\n",
" X=X\n",
" y=y\n",
" break"
],
"execution_count": 118,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "cmWr6faWYa1o"
},
"source": [
"def get_fashion_mnist_labels(labels):\n",
" text_labels=['t-shirt','trouser','pullover','dress','coat','sandal','shirt','sneaker','bag','ankle boot']\n",
" return text_labels[labels]"
],
"execution_count": 65,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "aX3XebRnZllw"
},
"source": [
"import pandas as pd"
],
"execution_count": 87,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "CmqvhH00aBYj"
},
"source": [
"def predict(X,y):\n",
" trl=[]\n",
" prel=[]\n",
" count = 0\n",
" X=X.as_in_ctx(d2l.try_gpu())\n",
" z=net(X).argmax(axis=1)\n",
" n=len(z)\n",
" for i,j in zip(z,y):\n",
" pre=get_fashion_mnist_labels(int(i))\n",
" tru = get_fashion_mnist_labels(int(j))\n",
" if pre==tru:\n",
" count+=1\n",
" trl.append(tru)\n",
" prel.append(pre)\n",
" label = {'true_label':trl,'predicted_label':prel}\n",
" df = pd.DataFrame(label)\n",
" print(df)\n",
" print('The accuracy:',(count/n)*100)"
],
"execution_count": 115,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "3042_7U1a66W",
"outputId": "825dad27-ab0e-48ab-af0b-f8bcc8ee6273"
},
"source": [
"predict(X[:10],y)"
],
"execution_count": 123,
"outputs": [
{
"output_type": "stream",
"text": [
" true_label predicted_label\n",
"0 t-shirt t-shirt\n",
"1 trouser trouser\n",
"2 pullover pullover\n",
"3 pullover shirt\n",
"4 dress dress\n",
"5 pullover shirt\n",
"6 bag bag\n",
"7 shirt pullover\n",
"8 sandal sandal\n",
"9 t-shirt t-shirt\n",
"The accuracy: 70.0\n"
],
"name": "stdout"
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment