{
 "cells": [
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "---\n",
    "execute:\n",
    "  enabled: false\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=alexnet-md-1 fw=all -->\n",
    "\n",
    "# The ImageNet Moment: AlexNet\n",
    "\n",
    "\n",
    "Although CNNs were well known in computer vision and machine learning\n",
    "following the introduction of LeNet [@LeCun.Jackel.Bottou.ea.1995],\n",
    "they did not immediately dominate the field. For much of the time between\n",
    "the early 1990s and the watershed results of 2012\n",
    "[@Krizhevsky.Sutskever.Hinton.2012], neural networks were often\n",
    "outperformed by other methods, such as kernel methods [@Scholkopf.Smola.2002],\n",
    "ensemble methods [@Freund.Schapire.ea.1996],\n",
    "and structured estimation [@Taskar.Guestrin.Koller.2004].\n",
    "\n",
    "For computer vision, this comparison is not entirely fair, because\n",
    "practitioners never fed raw pixels into traditional models. A typical\n",
    "pipeline preprocessed the images with hand-crafted feature extractors such as\n",
    "SIFT (the scale-invariant feature transform) [@Lowe.2004],\n",
    "SURF (speeded up robust features) [@Bay.Tuytelaars.Van-Gool.2006],\n",
    "or bags of visual words [@Sivic.Zisserman.2003], and only then trained\n",
    "a linear model or kernel method on the result. The features were *crafted*\n",
    "rather than *learned*: progress came from cleverer features and from deep\n",
    "insight into geometry [@Hartley.Zisserman.2000], and researchers\n",
    "believed, justifiably, that a slightly bigger or cleaner dataset or a\n",
    "slightly improved feature-extraction pipeline mattered far more to the final\n",
    "accuracy than the choice of classifier. The learning algorithm was an\n",
    "afterthought.\n",
    "\n",
    "Neural networks also faced real obstacles. The accelerators of the 1990s\n",
    "could not power deep multichannel, multilayer CNNs with many parameters,\n",
    "and datasets were small: OCR on 60,000 low-resolution $28 \\times 28$ pixel\n",
    "images was considered a highly challenging task. Key tricks for training\n",
    "neural networks were still missing, too, including parameter initialization\n",
    "heuristics [@Glorot.Bengio.2010], clever variants of stochastic gradient\n",
    "descent [@Kingma.Ba.2014], non-squashing activation functions\n",
    "[@Nair.Hinton.2010], and effective regularization\n",
    "[@Srivastava.Hinton.Krizhevsky.ea.2014]."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "alexnet-deep-convolutional-neural-networks-alexnet"
   },
   "source": [
    "from d2l import torch as d2l\n",
    "import torch\n",
    "from torch import nn"
   ],
   "execution_count": 1,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=alexnet-md-2 fw=all -->\n",
    "\n",
    "## Representation Learning\n",
    "\n",
    "Put differently, the most important part of the classical pipeline was the\n",
    "representation, and up until 2012 it was calculated mostly mechanically:\n",
    "SIFT, SURF, HOG (histograms of oriented gradient) [@Dalal.Triggs.2005],\n",
    "and bags of visual words ruled the roost.\n",
    "\n",
    "Another group of researchers, including Yann LeCun, Geoff Hinton, Yoshua\n",
    "Bengio, Andrew Ng, Shun-ichi Amari, and Juergen Schmidhuber, believed instead\n",
    "that features themselves ought to be learned, hierarchically composed from\n",
    "multiple jointly learned layers. The automatic design of visual features,\n",
    "such as those obtained by sparse coding [@olshausen1996emergence],\n",
    "remained an open challenge until\n",
    "@Dean.Corrado.Monga.ea.2012; @le2013building and the advent of modern\n",
    "CNNs.\n",
    "\n",
    "The first modern CNN [@Krizhevsky.Sutskever.Hinton.2012], named\n",
    "*AlexNet* after one of its inventors, Alex Krizhevsky, is largely an\n",
    "evolutionary improvement over LeNet. It won the 2012 ImageNet challenge and\n",
    "vindicated the bet on learning: in its lowest layers, the network learned\n",
    "feature extractors that resembled the traditional filters, as\n",
    "the figure shows. Higher layers build upon these representations\n",
    "to capture larger structures, like eyes, noses, and blades of grass, and yet\n",
    "higher layers whole objects, like people, airplanes, and dogs. Ultimately,\n",
    "the final hidden state is a compact representation of the image in which the\n",
    "different categories are easily separated.\n",
    "\n",
    "![Image filters learned by the first layer of AlexNet. Reproduction courtesy of @Krizhevsky.Sutskever.Hinton.2012.](../img/filters.png)\n",
    "\n",
    "AlexNet (2012) and its precursor LeNet (1995) share many architectural\n",
    "elements, which raises the question of why it took so long. The decisive\n",
    "difference is that, over the intervening two decades, the amount of data and\n",
    "the computing power available had each grown by orders of magnitude.\n",
    "\n",
    "### Missing Ingredient: Data\n",
    "\n",
    "Deep models with many layers require large amounts of data in order to enter\n",
    "the regime where they significantly outperform traditional methods based on\n",
    "convex optimization. However, given the limited storage, the expense of\n",
    "imaging sensors, and the tighter research budgets of the 1990s, most research\n",
    "relied on tiny datasets of hundreds or a few thousand low-resolution images,\n",
    "such as those in the UCI collection.\n",
    "\n",
    "The ImageNet dataset, released in 2009 [@Deng.Dong.Socher.ea.2009],\n",
    "changed this. The 2012 classification challenge supplied roughly 1.2 million\n",
    "training images across 1000 categories drawn from WordNet\n",
    "[@Miller.1995], prefiltered by web image search and verified by Amazon\n",
    "Mechanical Turk workers. Class sizes varied, and the source images had varying\n",
    "resolutions; models commonly trained on $224 \\times 224$ crops. The scale\n",
    "exceeded earlier labeled datasets by over an order of magnitude, while the\n",
    "source images retained far more detail than the $32 \\times 32$ thumbnails of\n",
    "the 80-million-image TinyImages dataset\n",
    "[@Torralba.Fergus.Freeman.2008], which allowed higher-level features to\n",
    "form. The associated competition, the ImageNet Large Scale Visual Recognition\n",
    "Challenge [@russakovsky2015imagenet], pushed computer vision and machine\n",
    "learning research to a scale that academics had not previously considered.\n",
    "\n",
    "### Missing Ingredient: Hardware\n",
    "\n",
    "Deep learning models are also voracious consumers of compute cycles: training\n",
    "can take hundreds of epochs, and each iteration passes data through many\n",
    "layers of expensive linear algebra operations. *Graphics processing units*\n",
    "(GPUs) changed the economics. These chips had been developed to accelerate\n",
    "computer graphics, in particular high-throughput $4 \\times 4$ matrix--vector\n",
    "products, math very similar to that of convolutional layers, and around that\n",
    "time NVIDIA and ATI had begun optimizing them for general computing\n",
    "[@Fernando.2004], marketing them as *general-purpose GPUs* (GPGPUs).\n",
    "Where a CPU core runs at a high clock frequency and spends most of its chip\n",
    "area on the machinery of general control flow (branch predictors, deep\n",
    "pipelines, speculative execution, large caches), a GPU packs thousands of\n",
    "much simpler cores onto one chip. This wins on power, since consumption grows\n",
    "roughly quadratically with clock frequency: for the budget of one CPU core\n",
    "running at four times the speed, 16 GPU cores at $\\frac{1}{4}$ the speed\n",
    "deliver $16 \\times \\frac{1}{4} = 4$ times the throughput. GPUs also have far\n",
    "wider memory buses, which matters because many deep learning operations are\n",
    "limited by memory bandwidth. A convolution applies the same small program at\n",
    "many output locations and channels, providing exactly this kind of\n",
    "independent work. The effect compounded quickly: between 1999, when NVIDIA's\n",
    "GeForce 256 processed roughly 480 million floating-point operations per\n",
    "second with no programming framework beyond graphics APIs, and 2012,\n",
    "consumer GPU throughput grew by roughly three orders of magnitude, and\n",
    "general-purpose GPU interfaces made it accessible without expressing the\n",
    "computation as a graphics pipeline.\n",
    "\n",
    "This was the situation in 2012 when Alex Krizhevsky and Ilya Sutskever\n",
    "implemented a deep CNN that could run on GPUs. They realized that the\n",
    "computational bottlenecks in CNNs, convolutions and matrix multiplications,\n",
    "are precisely the operations that GPUs parallelize well. Using two NVIDIA GTX\n",
    "580s with 3 GB of memory each, they implemented fast convolutions. The\n",
    "[cuda-convnet](https://code.google.com/archive/p/cuda-convnet/) code was good\n",
    "enough that for several years it was the industry standard and powered the\n",
    "first couple of years of the deep learning boom.\n",
    "\n",
    "## AlexNet\n",
    "\n",
    "AlexNet, which employed an 8-layer CNN,\n",
    "won the ImageNet Large Scale Visual Recognition Challenge 2012\n",
    "by a large margin [@Russakovsky.Deng.Huang.ea.2013].\n",
    "This network showed, for the first time,\n",
    "that the features obtained by learning can transcend manually designed features, breaking the previous paradigm in computer vision.\n",
    "\n",
    "The architectures of AlexNet and LeNet are closely related,\n",
    "as the figure illustrates.\n",
    "Note that we provide a slightly streamlined version of AlexNet\n",
    "removing some of the design quirks that were needed in 2012\n",
    "to make the model fit on two small GPUs.\n",
    "\n",
    "![LeNet (left) and AlexNet (right) side by side. Both consist of convolutional stages followed by a fully connected head; AlexNet is deeper and wider and replaces sigmoid activations with ReLU.](../img/arch-alexnet.svg)\n",
    "\n",
    "There are also key differences.\n",
    "First, AlexNet is much deeper than the comparatively small LeNet-5.\n",
    "AlexNet consists of eight layers: five convolutional layers,\n",
    "two fully connected hidden layers, and one fully connected output layer.\n",
    "Second, AlexNet used the ReLU instead of the sigmoid\n",
    "as its activation function.\n",
    "Let's look at the details.\n",
    "\n",
    "### Architecture\n",
    "\n",
    "In AlexNet's first layer, the convolution window shape is $11\\times11$.\n",
    "Since the images in ImageNet are eight times taller and wider\n",
    "than the MNIST images,\n",
    "objects in ImageNet data tend to occupy more pixels with more visual detail.\n",
    "Consequently, a larger convolution window is needed to capture the object.\n",
    "The convolution window shape in the second layer\n",
    "is reduced to $5\\times5$, followed by $3\\times3$.\n",
    "In addition, after the first, second, and fifth convolutional layers,\n",
    "the network adds max-pooling layers\n",
    "with a window shape of $3\\times3$ and a stride of 2.\n",
    "Moreover, AlexNet has ten times more convolution channels than LeNet.\n",
    "\n",
    "After the final convolutional layer, there are two huge fully connected layers\n",
    "with 4096 outputs each.\n",
    "Together they account for almost all of the model's parameters\n",
    "(over 160 MB in single precision).\n",
    "Because of the limited memory in early GPUs,\n",
    "the original AlexNet used a dual data stream design,\n",
    "so that each of their two GPUs could be responsible\n",
    "for storing and computing only its half of the model.\n",
    "GPU memory is rarely that scarce anymore,\n",
    "so our version of the model dispenses with the split.\n",
    "\n",
    "### Activation Functions\n",
    "\n",
    "AlexNet also changed the sigmoid activation function\n",
    "to the simpler ReLU activation function.\n",
    "This makes the computation cheaper,\n",
    "since the ReLU has no exponentiation operation,\n",
    "and, more importantly, it makes training easier:\n",
    "when the output of the sigmoid is very close to 0 or 1,\n",
    "its gradient is almost 0,\n",
    "so poorly initialized parameters may stop receiving updates,\n",
    "whereas the gradient of the ReLU in the positive interval\n",
    "is always 1 (that section).\n",
    "\n",
    "### Capacity Control and Preprocessing\n",
    "\n",
    "AlexNet controls the model complexity of the fully connected layer\n",
    "by dropout (that section),\n",
    "while LeNet only uses weight decay.\n",
    "To augment the data even further, the training loop of AlexNet\n",
    "added a great deal of image augmentation,\n",
    "such as flipping, clipping, and color changes.\n",
    "This exposes the model to many more variants of each image\n",
    "and thereby reduces overfitting;\n",
    "see @Buslaev.Iglovikov.Khvedchenya.ea.2020 for an in-depth\n",
    "review of such preprocessing steps.\n",
    "Augmentation and its descendants have since grown into a central part\n",
    "of how convolutional networks are trained,\n",
    "and we return to them in that section."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "alexnet-capacity-control-and-preprocessing-1"
   },
   "source": [
    "class AlexNet(d2l.Classifier):\n",
    "    def __init__(self, lr=0.1, num_classes=10):\n",
    "        super().__init__()\n",
    "        self.save_hyperparameters()\n",
    "        self.net = nn.Sequential(\n",
    "            nn.LazyConv2d(96, kernel_size=11, stride=4),\n",
    "            nn.ReLU(), nn.MaxPool2d(kernel_size=3, stride=2),\n",
    "            nn.LazyConv2d(256, kernel_size=5, padding=2), nn.ReLU(),\n",
    "            nn.MaxPool2d(kernel_size=3, stride=2),\n",
    "            nn.LazyConv2d(384, kernel_size=3, padding=1), nn.ReLU(),\n",
    "            nn.LazyConv2d(384, kernel_size=3, padding=1), nn.ReLU(),\n",
    "            nn.LazyConv2d(256, kernel_size=3, padding=1), nn.ReLU(),\n",
    "            nn.MaxPool2d(kernel_size=3, stride=2), nn.Flatten(),\n",
    "            nn.LazyLinear(4096), nn.ReLU(), nn.Dropout(p=0.5),\n",
    "            nn.LazyLinear(4096), nn.ReLU(),nn.Dropout(p=0.5),\n",
    "            nn.LazyLinear(num_classes))\n",
    "        # Note: lazy layers have no parameters at construction time, so weight\n",
    "        # initialization (d2l.init_cnn) is applied later via apply_init after\n",
    "        # a dummy forward pass materializes the parameters."
   ],
   "execution_count": 2,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=alexnet-md-3 fw=all -->\n",
    "\n",
    "We construct a single-channel data example with both height and width of 224 to observe the output shape of each layer. It matches the AlexNet architecture in the figure."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "alexnet-capacity-control-and-preprocessing-2"
   },
   "source": [
    "AlexNet().layer_summary((1, 1, 224, 224))"
   ],
   "execution_count": 3,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "Conv2d output shape:\t torch.Size([1, 96, 54, 54])\nReLU output shape:\t torch.Size([1, 96, 54, 54])\nMaxPool2d output shape:\t torch.Size([1, 96, 26, 26])\nConv2d output shape:\t torch.Size([1, 256, 26, 26])\nReLU output shape:\t torch.Size([1, 256, 26, 26])\nMaxPool2d output shape:\t torch.Size([1, 256, 12, 12])\nConv2d output shape:\t torch.Size([1, 384, 12, 12])\nReLU output shape:\t torch.Size([1, 384, 12, 12])\nConv2d output shape:\t torch.Size([1, 384, 12, 12])\nReLU output shape:\t torch.Size([1, 384, 12, 12])\nConv2d output shape:\t torch.Size([1, 256, 12, 12])\nReLU output shape:\t torch.Size([1, 256, 12, 12])\nMaxPool2d output shape:\t torch.Size([1, 256, 5, 5])\nFlatten output shape:\t torch.Size([1, 6400])\n"
     ]
    },
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "Linear output shape:\t torch.Size([1, 4096])\nReLU output shape:\t torch.Size([1, 4096])\nDropout output shape:\t torch.Size([1, 4096])\nLinear output shape:\t torch.Size([1, 4096])\nReLU output shape:\t torch.Size([1, 4096])\nDropout output shape:\t torch.Size([1, 4096])\nLinear output shape:\t torch.Size([1, 10])\n"
     ]
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=alexnet-md-4 fw=all -->\n",
    "\n",
    "## Training\n",
    "\n",
    "Although AlexNet was trained on ImageNet in @Krizhevsky.Sutskever.Hinton.2012,\n",
    "we use Fashion-MNIST here\n",
    "since training an ImageNet model to convergence could take hours or days\n",
    "even on a modern GPU.\n",
    "One of the problems with applying AlexNet directly on Fashion-MNIST\n",
    "is that its images have lower resolution ($28 \\times 28$ pixels)\n",
    "than ImageNet images.\n",
    "To make things work, we upsample them to $224 \\times 224$.\n",
    "This is generally not a smart practice, as it simply increases the computational\n",
    "complexity without adding information. Nonetheless, we do it here to be faithful to the AlexNet architecture.\n",
    "We perform this resizing with the `resize` argument in the `d2l.FashionMNIST` constructor.\n",
    "\n",
    "Now, we can start training AlexNet.\n",
    "Compared to LeNet in that section,\n",
    "the main change here is the use of a smaller learning rate\n",
    "and much slower training due to the deeper and wider network,\n",
    "the higher image resolution, and the more costly convolutions."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "alexnet-training"
   },
   "source": [
    "model = AlexNet(lr=0.01)\n",
    "data = d2l.FashionMNIST(batch_size=128, resize=(224, 224))\n",
    "trainer = d2l.Trainer(max_epochs=10, num_gpus=1)\n",
    "# Lazy layers have no weights at construction time; apply_init runs a\n",
    "# dummy forward pass to materialize parameters and then applies init_cnn.\n",
    "model.apply_init([next(iter(data.get_dataloader(True)))[0]], d2l.init_cnn)\n",
    "trainer.fit(model, data)"
   ],
   "execution_count": 4,
   "outputs": [
    {
     "output_type": "display_data",
     "data": {
      "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<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"238.965625pt\" height=\"183.35625pt\" viewBox=\"0 0 238.965625 183.35625\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n <metadata>\n  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n   <cc:Work>\n    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n    <dc:date>2026-07-19T13:44:31.430226</dc:date>\n    <dc:format>image/svg+xml</dc:format>\n    <dc:creator>\n     <cc:Agent>\n      <dc:title>Matplotlib v3.10.8, https://matplotlib.org/</dc:title>\n     </cc:Agent>\n    </dc:creator>\n   </cc:Work>\n  </rdf:RDF>\n </metadata>\n <defs>\n  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n </defs>\n <g id=\"figure_1\">\n  <g id=\"patch_1\">\n   <path d=\"M 0 183.35625 \nL 238.965625 183.35625 \nL 238.965625 0 \nL 0 0 \nz\n\" style=\"fill: #ffffff\"/>\n  </g>\n  <g id=\"axes_1\">\n   <g id=\"patch_2\">\n    <path d=\"M 30.103125 145.8 \nL 225.403125 145.8 \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      <defs>\n       <path id=\"mf2fdda8871\" d=\"M 0 0 \nL 0 3.5 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#mf2fdda8871\" x=\"30.103125\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_1\">\n      <!-- 0 -->\n      <g transform=\"translate(26.921875 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \nQ 1547 4250 1301 3770 \nQ 1056 3291 1056 2328 \nQ 1056 1369 1301 889 \nQ 1547 409 2034 409 \nQ 2525 409 2770 889 \nQ 3016 1369 3016 2328 \nQ 3016 3291 2770 3770 \nQ 2525 4250 2034 4250 \nz\nM 2034 4750 \nQ 2819 4750 3233 4129 \nQ 3647 3509 3647 2328 \nQ 3647 1150 3233 529 \nQ 2819 -91 2034 -91 \nQ 1250 -91 836 529 \nQ 422 1150 422 2328 \nQ 422 3509 836 4129 \nQ 1250 4750 2034 4750 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-30\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_2\">\n     <g id=\"line2d_2\">\n      <g>\n       <use xlink:href=\"#mf2fdda8871\" x=\"69.163125\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_2\">\n      <!-- 2 -->\n      <g transform=\"translate(65.981875 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-32\" d=\"M 1228 531 \nL 3431 531 \nL 3431 0 \nL 469 0 \nL 469 531 \nQ 828 903 1448 1529 \nQ 2069 2156 2228 2338 \nQ 2531 2678 2651 2914 \nQ 2772 3150 2772 3378 \nQ 2772 3750 2511 3984 \nQ 2250 4219 1831 4219 \nQ 1534 4219 1204 4116 \nQ 875 4013 500 3803 \nL 500 4441 \nQ 881 4594 1212 4672 \nQ 1544 4750 1819 4750 \nQ 2544 4750 2975 4387 \nQ 3406 4025 3406 3419 \nQ 3406 3131 3298 2873 \nQ 3191 2616 2906 2266 \nQ 2828 2175 2409 1742 \nQ 1991 1309 1228 531 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-32\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_3\">\n     <g id=\"line2d_3\">\n      <g>\n       <use xlink:href=\"#mf2fdda8871\" x=\"108.223125\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_3\">\n      <!-- 4 -->\n      <g transform=\"translate(105.041875 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \nL 825 1625 \nL 2419 1625 \nL 2419 4116 \nz\nM 2253 4666 \nL 3047 4666 \nL 3047 1625 \nL 3713 1625 \nL 3713 1100 \nL 3047 1100 \nL 3047 0 \nL 2419 0 \nL 2419 1100 \nL 313 1100 \nL 313 1709 \nL 2253 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-34\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_4\">\n     <g id=\"line2d_4\">\n      <g>\n       <use xlink:href=\"#mf2fdda8871\" x=\"147.283125\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_4\">\n      <!-- 6 -->\n      <g transform=\"translate(144.101875 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-36\" d=\"M 2113 2584 \nQ 1688 2584 1439 2293 \nQ 1191 2003 1191 1497 \nQ 1191 994 1439 701 \nQ 1688 409 2113 409 \nQ 2538 409 2786 701 \nQ 3034 994 3034 1497 \nQ 3034 2003 2786 2293 \nQ 2538 2584 2113 2584 \nz\nM 3366 4563 \nL 3366 3988 \nQ 3128 4100 2886 4159 \nQ 2644 4219 2406 4219 \nQ 1781 4219 1451 3797 \nQ 1122 3375 1075 2522 \nQ 1259 2794 1537 2939 \nQ 1816 3084 2150 3084 \nQ 2853 3084 3261 2657 \nQ 3669 2231 3669 1497 \nQ 3669 778 3244 343 \nQ 2819 -91 2113 -91 \nQ 1303 -91 875 529 \nQ 447 1150 447 2328 \nQ 447 3434 972 4092 \nQ 1497 4750 2381 4750 \nQ 2619 4750 2861 4703 \nQ 3103 4656 3366 4563 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-36\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_5\">\n     <g id=\"line2d_5\">\n      <g>\n       <use xlink:href=\"#mf2fdda8871\" x=\"186.343125\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_5\">\n      <!-- 8 -->\n      <g transform=\"translate(183.161875 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-38\" d=\"M 2034 2216 \nQ 1584 2216 1326 1975 \nQ 1069 1734 1069 1313 \nQ 1069 891 1326 650 \nQ 1584 409 2034 409 \nQ 2484 409 2743 651 \nQ 3003 894 3003 1313 \nQ 3003 1734 2745 1975 \nQ 2488 2216 2034 2216 \nz\nM 1403 2484 \nQ 997 2584 770 2862 \nQ 544 3141 544 3541 \nQ 544 4100 942 4425 \nQ 1341 4750 2034 4750 \nQ 2731 4750 3128 4425 \nQ 3525 4100 3525 3541 \nQ 3525 3141 3298 2862 \nQ 3072 2584 2669 2484 \nQ 3125 2378 3379 2068 \nQ 3634 1759 3634 1313 \nQ 3634 634 3220 271 \nQ 2806 -91 2034 -91 \nQ 1263 -91 848 271 \nQ 434 634 434 1313 \nQ 434 1759 690 2068 \nQ 947 2378 1403 2484 \nz\nM 1172 3481 \nQ 1172 3119 1398 2916 \nQ 1625 2713 2034 2713 \nQ 2441 2713 2670 2916 \nQ 2900 3119 2900 3481 \nQ 2900 3844 2670 4047 \nQ 2441 4250 2034 4250 \nQ 1625 4250 1398 4047 \nQ 1172 3844 1172 3481 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-38\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_6\">\n     <g id=\"line2d_6\">\n      <g>\n       <use xlink:href=\"#mf2fdda8871\" x=\"225.403125\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_6\">\n      <!-- 10 -->\n      <g transform=\"translate(219.040625 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-31\" d=\"M 794 531 \nL 1825 531 \nL 1825 4091 \nL 703 3866 \nL 703 4441 \nL 1819 4666 \nL 2450 4666 \nL 2450 531 \nL 3481 531 \nL 3481 0 \nL 794 0 \nL 794 531 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-31\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"text_7\">\n     <!-- epoch -->\n     <g transform=\"translate(112.525 174.076563) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \nL 3597 1613 \nL 953 1613 \nQ 991 1019 1311 708 \nQ 1631 397 2203 397 \nQ 2534 397 2845 478 \nQ 3156 559 3463 722 \nL 3463 178 \nQ 3153 47 2828 -22 \nQ 2503 -91 2169 -91 \nQ 1331 -91 842 396 \nQ 353 884 353 1716 \nQ 353 2575 817 3079 \nQ 1281 3584 2069 3584 \nQ 2775 3584 3186 3129 \nQ 3597 2675 3597 1894 \nz\nM 3022 2063 \nQ 3016 2534 2758 2815 \nQ 2500 3097 2075 3097 \nQ 1594 3097 1305 2825 \nQ 1016 2553 972 2059 \nL 3022 2063 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-70\" d=\"M 1159 525 \nL 1159 -1331 \nL 581 -1331 \nL 581 3500 \nL 1159 3500 \nL 1159 2969 \nQ 1341 3281 1617 3432 \nQ 1894 3584 2278 3584 \nQ 2916 3584 3314 3078 \nQ 3713 2572 3713 1747 \nQ 3713 922 3314 415 \nQ 2916 -91 2278 -91 \nQ 1894 -91 1617 61 \nQ 1341 213 1159 525 \nz\nM 3116 1747 \nQ 3116 2381 2855 2742 \nQ 2594 3103 2138 3103 \nQ 1681 3103 1420 2742 \nQ 1159 2381 1159 1747 \nQ 1159 1113 1420 752 \nQ 1681 391 2138 391 \nQ 2594 391 2855 752 \nQ 3116 1113 3116 1747 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-6f\" d=\"M 1959 3097 \nQ 1497 3097 1228 2736 \nQ 959 2375 959 1747 \nQ 959 1119 1226 758 \nQ 1494 397 1959 397 \nQ 2419 397 2687 759 \nQ 2956 1122 2956 1747 \nQ 2956 2369 2687 2733 \nQ 2419 3097 1959 3097 \nz\nM 1959 3584 \nQ 2709 3584 3137 3096 \nQ 3566 2609 3566 1747 \nQ 3566 888 3137 398 \nQ 2709 -91 1959 -91 \nQ 1206 -91 779 398 \nQ 353 888 353 1747 \nQ 353 2609 779 3096 \nQ 1206 3584 1959 3584 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-63\" d=\"M 3122 3366 \nL 3122 2828 \nQ 2878 2963 2633 3030 \nQ 2388 3097 2138 3097 \nQ 1578 3097 1268 2742 \nQ 959 2388 959 1747 \nQ 959 1106 1268 751 \nQ 1578 397 2138 397 \nQ 2388 397 2633 464 \nQ 2878 531 3122 666 \nL 3122 134 \nQ 2881 22 2623 -34 \nQ 2366 -91 2075 -91 \nQ 1284 -91 818 406 \nQ 353 903 353 1747 \nQ 353 2603 823 3093 \nQ 1294 3584 2113 3584 \nQ 2378 3584 2631 3529 \nQ 2884 3475 3122 3366 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-68\" d=\"M 3513 2113 \nL 3513 0 \nL 2938 0 \nL 2938 2094 \nQ 2938 2591 2744 2837 \nQ 2550 3084 2163 3084 \nQ 1697 3084 1428 2787 \nQ 1159 2491 1159 1978 \nL 1159 0 \nL 581 0 \nL 581 4863 \nL 1159 4863 \nL 1159 2956 \nQ 1366 3272 1645 3428 \nQ 1925 3584 2291 3584 \nQ 2894 3584 3203 3211 \nQ 3513 2838 3513 2113 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#DejaVuSans-65\"/>\n      <use xlink:href=\"#DejaVuSans-70\" transform=\"translate(61.523438 0)\"/>\n      <use xlink:href=\"#DejaVuSans-6f\" transform=\"translate(125 0)\"/>\n      <use xlink:href=\"#DejaVuSans-63\" transform=\"translate(186.181641 0)\"/>\n      <use xlink:href=\"#DejaVuSans-68\" transform=\"translate(241.162109 0)\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"matplotlib.axis_2\">\n    <g id=\"ytick_1\">\n     <g id=\"line2d_7\">\n      <defs>\n       <path id=\"mee04e8ce8c\" d=\"M 0 0 \nL -3.5 0 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#mee04e8ce8c\" x=\"30.103125\" y=\"124.646957\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_8\">\n      <!-- 0.5 -->\n      <g transform=\"translate(7.2 128.446176) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-2e\" d=\"M 684 794 \nL 1344 794 \nL 1344 0 \nL 684 0 \nL 684 794 \nz\n\" transform=\"scale(0.015625)\"/>\n        <path id=\"DejaVuSans-35\" d=\"M 691 4666 \nL 3169 4666 \nL 3169 4134 \nL 1269 4134 \nL 1269 2991 \nQ 1406 3038 1543 3061 \nQ 1681 3084 1819 3084 \nQ 2600 3084 3056 2656 \nQ 3513 2228 3513 1497 \nQ 3513 744 3044 326 \nQ 2575 -91 1722 -91 \nQ 1428 -91 1123 -41 \nQ 819 9 494 109 \nL 494 744 \nQ 775 591 1075 516 \nQ 1375 441 1709 441 \nQ 2250 441 2565 725 \nQ 2881 1009 2881 1497 \nQ 2881 1984 2565 2268 \nQ 2250 2553 1709 2553 \nQ 1456 2553 1204 2497 \nQ 953 2441 691 2322 \nL 691 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-30\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-35\" transform=\"translate(95.410156 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_2\">\n     <g id=\"line2d_8\">\n      <g>\n       <use xlink:href=\"#mee04e8ce8c\" x=\"30.103125\" y=\"82.762205\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_9\">\n      <!-- 1.0 -->\n      <g transform=\"translate(7.2 86.561424) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-31\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(95.410156 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_3\">\n     <g id=\"line2d_9\">\n      <g>\n       <use xlink:href=\"#mee04e8ce8c\" x=\"30.103125\" y=\"40.877454\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_10\">\n      <!-- 1.5 -->\n      <g transform=\"translate(7.2 44.676672) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-31\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-35\" transform=\"translate(95.410156 0)\"/>\n      </g>\n     </g>\n    </g>\n   </g>\n   <g id=\"line2d_10\">\n    <path d=\"M 34.954394 13.5 \nL 44.698573 93.561785 \nL 54.442752 108.200705 \nL 64.186931 114.417031 \nL 73.93111 119.637688 \nL 83.675289 122.834303 \nL 93.419468 125.88274 \nL 103.163647 127.086328 \nL 112.907826 129.391809 \nL 122.652006 130.725401 \nL 132.396185 132.306599 \nL 142.140364 133.335877 \nL 151.884543 134.107785 \nL 161.628722 135.691367 \nL 171.372901 136.340807 \nL 181.11708 136.519425 \nL 190.861259 137.704653 \nL 200.605438 138.128534 \nL 210.349618 138.480375 \nL 220.093797 139.339931 \n\" clip-path=\"url(#p94af68c9f5)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n   </g>\n   <g id=\"line2d_11\">\n    <path d=\"M 49.633125 105.214077 \nL 69.163125 120.588763 \nL 88.693125 126.068768 \nL 108.223125 128.970244 \nL 127.753125 131.794261 \nL 147.283125 134.52908 \nL 166.813125 136.280162 \nL 186.343125 137.703175 \nL 205.873125 138.361049 \nL 225.403125 139.5 \n\" clip-path=\"url(#p94af68c9f5)\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #ff7f0e; stroke-width: 1.5\"/>\n   </g>\n   <g id=\"line2d_12\">\n    <path d=\"M 49.633125 105.303426 \nL 69.163125 99.637055 \nL 88.693125 98.013358 \nL 108.223125 96.787301 \nL 127.753125 95.644086 \nL 147.283125 94.36004 \nL 166.813125 93.771864 \nL 186.343125 93.258246 \nL 205.873125 92.984868 \nL 225.403125 92.595512 \n\" clip-path=\"url(#p94af68c9f5)\" style=\"fill: none; stroke-dasharray: 9.6,2.4,1.5,2.4; stroke-dashoffset: 0; stroke: #2ca02c; stroke-width: 1.5\"/>\n   </g>\n   <g id=\"patch_3\">\n    <path d=\"M 30.103125 145.8 \nL 30.103125 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_4\">\n    <path d=\"M 225.403125 145.8 \nL 225.403125 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_5\">\n    <path d=\"M 30.103125 145.8 \nL 225.403125 145.8 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\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-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"legend_1\">\n    <g id=\"patch_7\">\n     <path d=\"M 138.8125 60.06875 \nL 218.403125 60.06875 \nQ 220.403125 60.06875 220.403125 58.06875 \nL 220.403125 14.2 \nQ 220.403125 12.2 218.403125 12.2 \nL 138.8125 12.2 \nQ 136.8125 12.2 136.8125 14.2 \nL 136.8125 58.06875 \nQ 136.8125 60.06875 138.8125 60.06875 \nz\n\" style=\"fill: #ffffff; opacity: 0.8; stroke: #cccccc; stroke-linejoin: miter\"/>\n    </g>\n    <g id=\"line2d_13\">\n     <path d=\"M 140.8125 20.298438 \nL 150.8125 20.298438 \nL 160.8125 20.298438 \n\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n    </g>\n    <g id=\"text_11\">\n     <!-- train_loss -->\n     <g transform=\"translate(168.8125 23.798438) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"DejaVuSans-74\" d=\"M 1172 4494 \nL 1172 3500 \nL 2356 3500 \nL 2356 3053 \nL 1172 3053 \nL 1172 1153 \nQ 1172 725 1289 603 \nQ 1406 481 1766 481 \nL 2356 481 \nL 2356 0 \nL 1766 0 \nQ 1100 0 847 248 \nQ 594 497 594 1153 \nL 594 3053 \nL 172 3053 \nL 172 3500 \nL 594 3500 \nL 594 4494 \nL 1172 4494 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-72\" d=\"M 2631 2963 \nQ 2534 3019 2420 3045 \nQ 2306 3072 2169 3072 \nQ 1681 3072 1420 2755 \nQ 1159 2438 1159 1844 \nL 1159 0 \nL 581 0 \nL 581 3500 \nL 1159 3500 \nL 1159 2956 \nQ 1341 3275 1631 3429 \nQ 1922 3584 2338 3584 \nQ 2397 3584 2469 3576 \nQ 2541 3569 2628 3553 \nL 2631 2963 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-61\" d=\"M 2194 1759 \nQ 1497 1759 1228 1600 \nQ 959 1441 959 1056 \nQ 959 750 1161 570 \nQ 1363 391 1709 391 \nQ 2188 391 2477 730 \nQ 2766 1069 2766 1631 \nL 2766 1759 \nL 2194 1759 \nz\nM 3341 1997 \nL 3341 0 \nL 2766 0 \nL 2766 531 \nQ 2569 213 2275 61 \nQ 1981 -91 1556 -91 \nQ 1019 -91 701 211 \nQ 384 513 384 1019 \nQ 384 1609 779 1909 \nQ 1175 2209 1959 2209 \nL 2766 2209 \nL 2766 2266 \nQ 2766 2663 2505 2880 \nQ 2244 3097 1772 3097 \nQ 1472 3097 1187 3025 \nQ 903 2953 641 2809 \nL 641 3341 \nQ 956 3463 1253 3523 \nQ 1550 3584 1831 3584 \nQ 2591 3584 2966 3190 \nQ 3341 2797 3341 1997 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-69\" d=\"M 603 3500 \nL 1178 3500 \nL 1178 0 \nL 603 0 \nL 603 3500 \nz\nM 603 4863 \nL 1178 4863 \nL 1178 4134 \nL 603 4134 \nL 603 4863 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-6e\" d=\"M 3513 2113 \nL 3513 0 \nL 2938 0 \nL 2938 2094 \nQ 2938 2591 2744 2837 \nQ 2550 3084 2163 3084 \nQ 1697 3084 1428 2787 \nQ 1159 2491 1159 1978 \nL 1159 0 \nL 581 0 \nL 581 3500 \nL 1159 3500 \nL 1159 2956 \nQ 1366 3272 1645 3428 \nQ 1925 3584 2291 3584 \nQ 2894 3584 3203 3211 \nQ 3513 2838 3513 2113 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-5f\" d=\"M 3263 -1063 \nL 3263 -1509 \nL -63 -1509 \nL -63 -1063 \nL 3263 -1063 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-6c\" d=\"M 603 4863 \nL 1178 4863 \nL 1178 0 \nL 603 0 \nL 603 4863 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-73\" d=\"M 2834 3397 \nL 2834 2853 \nQ 2591 2978 2328 3040 \nQ 2066 3103 1784 3103 \nQ 1356 3103 1142 2972 \nQ 928 2841 928 2578 \nQ 928 2378 1081 2264 \nQ 1234 2150 1697 2047 \nL 1894 2003 \nQ 2506 1872 2764 1633 \nQ 3022 1394 3022 966 \nQ 3022 478 2636 193 \nQ 2250 -91 1575 -91 \nQ 1294 -91 989 -36 \nQ 684 19 347 128 \nL 347 722 \nQ 666 556 975 473 \nQ 1284 391 1588 391 \nQ 1994 391 2212 530 \nQ 2431 669 2431 922 \nQ 2431 1156 2273 1281 \nQ 2116 1406 1581 1522 \nL 1381 1569 \nQ 847 1681 609 1914 \nQ 372 2147 372 2553 \nQ 372 3047 722 3315 \nQ 1072 3584 1716 3584 \nQ 2034 3584 2315 3537 \nQ 2597 3491 2834 3397 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#DejaVuSans-74\"/>\n      <use xlink:href=\"#DejaVuSans-72\" transform=\"translate(39.208984 0)\"/>\n      <use xlink:href=\"#DejaVuSans-61\" transform=\"translate(80.322266 0)\"/>\n      <use xlink:href=\"#DejaVuSans-69\" transform=\"translate(141.601562 0)\"/>\n      <use xlink:href=\"#DejaVuSans-6e\" transform=\"translate(169.384766 0)\"/>\n      <use xlink:href=\"#DejaVuSans-5f\" transform=\"translate(232.763672 0)\"/>\n      <use xlink:href=\"#DejaVuSans-6c\" transform=\"translate(282.763672 0)\"/>\n      <use xlink:href=\"#DejaVuSans-6f\" transform=\"translate(310.546875 0)\"/>\n      <use xlink:href=\"#DejaVuSans-73\" transform=\"translate(371.728516 0)\"/>\n      <use xlink:href=\"#DejaVuSans-73\" transform=\"translate(423.828125 0)\"/>\n     </g>\n    </g>\n    <g id=\"line2d_14\">\n     <path d=\"M 140.8125 35.254688 \nL 150.8125 35.254688 \nL 160.8125 35.254688 \n\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #ff7f0e; stroke-width: 1.5\"/>\n    </g>\n    <g id=\"text_12\">\n     <!-- val_loss -->\n     <g transform=\"translate(168.8125 38.754688) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"DejaVuSans-76\" d=\"M 191 3500 \nL 800 3500 \nL 1894 563 \nL 2988 3500 \nL 3597 3500 \nL 2284 0 \nL 1503 0 \nL 191 3500 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#DejaVuSans-76\"/>\n      <use xlink:href=\"#DejaVuSans-61\" transform=\"translate(59.179688 0)\"/>\n      <use xlink:href=\"#DejaVuSans-6c\" transform=\"translate(120.458984 0)\"/>\n      <use xlink:href=\"#DejaVuSans-5f\" transform=\"translate(148.242188 0)\"/>\n      <use xlink:href=\"#DejaVuSans-6c\" transform=\"translate(198.242188 0)\"/>\n      <use xlink:href=\"#DejaVuSans-6f\" transform=\"translate(226.025391 0)\"/>\n      <use xlink:href=\"#DejaVuSans-73\" transform=\"translate(287.207031 0)\"/>\n      <use xlink:href=\"#DejaVuSans-73\" transform=\"translate(339.306641 0)\"/>\n     </g>\n    </g>\n    <g id=\"line2d_15\">\n     <path d=\"M 140.8125 50.210938 \nL 150.8125 50.210938 \nL 160.8125 50.210938 \n\" style=\"fill: none; stroke-dasharray: 9.6,2.4,1.5,2.4; stroke-dashoffset: 0; stroke: #2ca02c; stroke-width: 1.5\"/>\n    </g>\n    <g id=\"text_13\">\n     <!-- val_acc -->\n     <g transform=\"translate(168.8125 53.710938) scale(0.1 -0.1)\">\n      <use xlink:href=\"#DejaVuSans-76\"/>\n      <use xlink:href=\"#DejaVuSans-61\" transform=\"translate(59.179688 0)\"/>\n      <use xlink:href=\"#DejaVuSans-6c\" transform=\"translate(120.458984 0)\"/>\n      <use xlink:href=\"#DejaVuSans-5f\" transform=\"translate(148.242188 0)\"/>\n      <use xlink:href=\"#DejaVuSans-61\" transform=\"translate(198.242188 0)\"/>\n      <use xlink:href=\"#DejaVuSans-63\" transform=\"translate(259.521484 0)\"/>\n      <use xlink:href=\"#DejaVuSans-63\" transform=\"translate(314.501953 0)\"/>\n     </g>\n    </g>\n   </g>\n  </g>\n </g>\n <defs>\n  <clipPath id=\"p94af68c9f5\">\n   <rect x=\"30.103125\" y=\"7.2\" width=\"195.3\" height=\"138.6\"/>\n  </clipPath>\n </defs>\n</svg>\n"
     },
     "metadata": {}
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=alexnet-md-5 fw=all -->\n",
    "\n",
    "## Discussion\n",
    "\n",
    "AlexNet's structure bears a close resemblance to LeNet, with a number of critical improvements, both for accuracy (dropout) and for ease of training (ReLU). Equally consequential is the progress in deep learning tooling: what was several months of work in 2012 can now be accomplished in a dozen lines of code using any modern framework.\n",
    "\n",
    "Reviewing the architecture, we see that AlexNet has an Achilles heel when it comes to efficiency: the last two hidden layers require matrices of size $6400 \\times 4096$ and $4096 \\times 4096$, respectively. This corresponds to 164 MB of memory and 81 MFLOPs of computation, both of which are a nontrivial outlay, especially on smaller devices, such as mobile phones. This is one of the reasons why AlexNet has been surpassed by much more effective architectures that we will cover in the following sections. Nonetheless, it is a key step from shallow to deep networks that are used nowadays. Note that even though the number of parameters exceeds by far the amount of training data in our experiments (the last two layers have more than 40 million parameters, trained on a dataset of 60 thousand images), there is hardly any overfitting: training and validation loss are virtually identical throughout training. This is due to the improved regularization, such as dropout, inherent in modern deep network designs.\n",
    "\n",
    "Although it seems that there are only a few more lines in AlexNet's implementation than in LeNet's, it took the academic community many years to embrace this conceptual change and take advantage of its excellent experimental results. This was also due to the lack of efficient computational tools. At the time neither DistBelief [@Dean.Corrado.Monga.ea.2012] nor Caffe [@Jia.Shelhamer.Donahue.ea.2014] existed, and Theano [@Bergstra.Breuleux.Bastien.ea.2010], the first widely used automatic-differentiation framework, still lacked many features its successors would bring. It was the maturation of such frameworks, from Theano to TensorFlow [@Abadi.Barham.Chen.ea.2016] and later PyTorch [@Paszke.Gross.Massa.ea.2019] and JAX [@Frostig.Johnson.Leary.2018], that turned implementing a new architecture from an engineering project into routine work.\n",
    "\n",
    "## Exercises\n",
    "\n",
    "1. Following up on the discussion above, analyze the computational properties of AlexNet.\n",
    "    1. Compute the memory footprint for convolutions and fully connected layers, respectively. Which one dominates?\n",
    "    1. Calculate the computational cost for the convolutions and the fully connected layers.\n",
    "    1. How does the memory (read and write bandwidth, latency, size) affect computation? Is there any difference in its effects for training and inference?\n",
    "1. You are a chip designer and need to trade off computation and memory bandwidth. For example, a faster chip requires more power and possibly a larger chip area. More memory bandwidth requires more pins and control logic, thus also more area. How do you optimize?\n",
    "1. Why do engineers no longer report performance benchmarks on AlexNet?\n",
    "1. Try increasing the number of epochs when training AlexNet. Compared with LeNet, how do the results differ? Why?\n",
    "1. AlexNet may be too complex for the Fashion-MNIST dataset, in particular due to the low resolution of the initial images.\n",
    "    1. Try simplifying the model to make the training faster, while ensuring that the accuracy does not drop significantly.\n",
    "    1. Design a better model that works directly on $28 \\times 28$ images.\n",
    "1. Modify the batch size, and observe the changes in throughput (images/s), accuracy, and GPU memory.\n",
    "1. Apply dropout and ReLU to LeNet-5. Does it improve? Can you improve things further by preprocessing to take advantage of the invariances inherent in the images?\n",
    "1. Can you make AlexNet overfit? Which feature do you need to remove or change to break training?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=alexnet-md-6 fw=pytorch -->\n",
    "\n",
    "[Discussions](https://d2l.discourse.group/t/76)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "name": "d2l-pytorch",
   "display_name": "d2l (PyTorch)",
   "language": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
