{
 "cells": [
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "---\n",
    "execute:\n",
    "  enabled: false\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=dcgan-md-1 fw=all -->\n",
    "\n",
    "# Deep Convolutional Generative Adversarial Networks\n",
    "\n",
    "In that section, we introduced the basic ideas behind how GANs work. We showed that they can draw samples from some simple, easy-to-sample distribution, like a uniform or normal distribution, and transform them into samples that appear to match the distribution of some dataset. And while our example of matching a 2D Gaussian distribution got the point across, it is not especially exciting.\n",
    "\n",
    "In this section, we will demonstrate how you can use GANs to generate photorealistic images. We will be basing our models on the deep convolutional GANs (DCGAN) introduced in @Radford.Metz.Chintala.2015 . We will borrow the convolutional architectures that have proven so successful for discriminative computer vision problems and show how via GANs, they can be leveraged to generate photorealistic images."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "dcgan-deep-convolutional-generative-adversarial-networks"
   },
   "source": [
    "from mxnet import gluon, init, np, npx\n",
    "from mxnet.gluon import nn\n",
    "from d2l import mxnet as d2l\n",
    "\n",
    "npx.set_np()"
   ],
   "execution_count": 1,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=dcgan-md-2 fw=all -->\n",
    "\n",
    "## The Pokemon Dataset\n",
    "\n",
    "The dataset we will use is a collection of Pokemon sprites obtained from [pokemondb](https://pokemondb.net/sprites). First download, extract and load this dataset."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "dcgan-the-pokemon-dataset-1"
   },
   "source": [
    "\n",
    "d2l.DATA_HUB['pokemon'] = (d2l.DATA_URL + 'pokemon.zip',\n",
    "                           'c065c0e2593b8b161a2d7873e42418bf6a21106c')\n",
    "\n",
    "data_dir = d2l.download_extract('pokemon')\n",
    "pokemon = gluon.data.vision.datasets.ImageFolderDataset(data_dir)"
   ],
   "execution_count": 2,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=dcgan-md-3 fw=all -->\n",
    "\n",
    "We resize each image into $64\\times 64$. The `ToTensor` transformation will project the pixel value into $[0, 1]$, while our generator will use the tanh function to obtain outputs in $[-1, 1]$. Therefore we normalize the data with $0.5$ mean and $0.5$ standard deviation to match the value range."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "dcgan-the-pokemon-dataset-2"
   },
   "source": [
    "batch_size = 256\n",
    "transformer = gluon.data.vision.transforms.Compose([\n",
    "    gluon.data.vision.transforms.Resize(64),\n",
    "    gluon.data.vision.transforms.ToTensor(),\n",
    "    gluon.data.vision.transforms.Normalize(0.5, 0.5)\n",
    "])\n",
    "data_iter = gluon.data.DataLoader(\n",
    "    pokemon.transform_first(transformer), batch_size=batch_size,\n",
    "    shuffle=True, num_workers=d2l.get_dataloader_workers())"
   ],
   "execution_count": 3,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=dcgan-md-4 fw=all -->\n",
    "\n",
    "Let's visualize the first 20 images."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "dcgan-the-pokemon-dataset-3"
   },
   "source": [
    "d2l.set_figsize((4, 4))\n",
    "for X, y in data_iter:\n",
    "    imgs = X[:20,:,:,:].transpose(0, 2, 3, 1)/2+0.5\n",
    "    d2l.show_images(imgs, num_rows=4, num_cols=5)\n",
    "    break"
   ],
   "execution_count": 4,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stderr",
     "text": [
      "[15:26:52] /home/smola/mxnet/src/imperative/./../common/../common/utils.h:521: \nStorage type fallback detected:\noperator = stack\ninput storage types = [default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, ]\noutput storage types = [default, ]\nparams = {}\ncontext.dev_mask = cpu\n WARNING:\nExecution of the operator above will fallback to the generic implementation (not utilizing kernels from oneDNN library) with default dense storage type. You are seeing this warning message because MXNET_ONEDNN_ENABLED flag is set to 0, in which case you can re-enable the default execution path by setting MXNET_ONEDNN_ENABLED back to 1, or the operator above is unable to process the given ndarrays with specified storage types, context and/or parameter, in which case temporary dense ndarrays are generated in order to execute the operator. The fallback does not affect the correctness of the programme. Using default storage type performance degradation might be observed. \nYou can set environment variable MXNET_STORAGE_FALLBACK_LOG_VERBOSE to 0 to suppress this warning.\n[15:26:52] /home/smola/mxnet/src/imperative/./../common/../common/utils.h:521: \nStorage type fallback detected:\noperator = stack\ninput storage types = [default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, ]\noutput storage types = [default, ]\nparams = {}\ncontext.dev_mask = cpu\n WARNING:\nExecution of the operator above will fallback to the generic implementation (not utilizing kernels from oneDNN library) with default dense storage type. You are seeing this warning message because MXNET_ONEDNN_ENABLED flag is set to 0, in which case you can re-enable the default execution path by setting MXNET_ONEDNN_ENABLED back to 1, or the operator above is unable to process the given ndarrays with specified storage types, context and/or parameter, in which case temporary dense ndarrays are generated in order to execute the operator. The fallback does not affect the correctness of the programme. Using default storage type performance degradation might be observed. \nYou can set environment variable MXNET_STORAGE_FALLBACK_LOG_VERBOSE to 0 to suppress this warning.\n[15:26:52] /home/smola/mxnet/src/imperative/./../common/../common/utils.h:521: \nStorage type fallback detected:\noperator = stack\ninput storage types = [default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, ]\noutput storage types = [default, ]\nparams = {}\ncontext.dev_mask = cpu\n WARNING:\nExecution of the operator above will fallback to the generic implementation (not utilizing kernels from oneDNN library) with default dense storage type. You are seeing this warning message because MXNET_ONEDNN_ENABLED flag is set to 0, in which case you can re-enable the default execution path by setting MXNET_ONEDNN_ENABLED back to 1, or the operator above is unable to process the given ndarrays with specified storage types, context and/or parameter, in which case temporary dense ndarrays are generated in order to execute the operator. The fallback does not affect the correctness of the programme. Using default storage type performance degradation might be observed. \nYou can set environment variable MXNET_STORAGE_FALLBACK_LOG_VERBOSE to 0 to suppress this warning.\n[15:26:52] /home/smola/mxnet/src/imperative/./../common/../common/utils.h:521: \nStorage type fallback detected:\noperator = stack\ninput storage types = [default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, default, ]\noutput storage types = [default, ]\nparams = {}\ncontext.dev_mask = cpu\n WARNING:\nExecution of the operator above will fallback to the generic implementation (not utilizing kernels from oneDNN library) with default dense storage type. You are seeing this warning message because MXNET_ONEDNN_ENABLED flag is set to 0, in which case you can re-enable the default execution path by setting MXNET_ONEDNN_ENABLED back to 1, or the operator above is unable to process the given ndarrays with specified storage types, context and/or parameter, in which case temporary dense ndarrays are generated in order to execute the operator. The fallback does not affect the correctness of the programme. Using default storage type performance degradation might be observed. \nYou can set environment variable MXNET_STORAGE_FALLBACK_LOG_VERBOSE to 0 to suppress this warning.\n"
     ]
    },
    {
     "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=\"432.9pt\" height=\"346.882129pt\" viewBox=\"0 0 432.9 346.882129\" 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-19T15:26:52.705922</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 346.882129 \nL 432.9 346.882129 \nL 432.9 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 7.2 79.355172 \nL 79.355172 79.355172 \nL 79.355172 7.2 \nL 7.2 7.2 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#pd5d609d1eb)\">\n    <image xlink:href=\"data:image/png;base64,\[encoded data, 18745 characters]\" id=\"imagea012f1437f\" transform=\"scale(1 -1) translate(0 -72.72)\" x=\"7.2\" y=\"-6.635172\" width=\"72.72\" height=\"72.72\"/>\n   </g>\n   <g id=\"patch_3\">\n    <path d=\"M 7.2 79.355172 \nL 7.2 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 79.355172 79.355172 \nL 79.355172 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 7.2 79.355172 \nL 79.355172 79.355172 \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 7.2 7.2 \nL 79.355172 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n  </g>\n  <g id=\"axes_2\">\n   <g id=\"patch_7\">\n    <path d=\"M 93.786207 79.355172 \nL 165.941379 79.355172 \nL 165.941379 7.2 \nL 93.786207 7.2 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#pc9c75718df)\">\n    <image xlink:href=\"data:image/png;base64,\[encoded data, 18113 characters]\" id=\"imageeb1a5e44e2\" transform=\"scale(1 -1) translate(0 -72.72)\" x=\"93.786207\" y=\"-6.635172\" width=\"72.72\" height=\"72.72\"/>\n   </g>\n   <g id=\"patch_8\">\n    <path d=\"M 93.786207 79.355172 \nL 93.786207 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_9\">\n    <path d=\"M 165.941379 79.355172 \nL 165.941379 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_10\">\n    <path d=\"M 93.786207 79.355172 \nL 165.941379 79.355172 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_11\">\n    <path d=\"M 93.786207 7.2 \nL 165.941379 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n  </g>\n  <g id=\"axes_3\">\n   <g id=\"patch_12\">\n    <path d=\"M 180.372414 79.355172 \nL 252.527586 79.355172 \nL 252.527586 7.2 \nL 180.372414 7.2 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#pa834f822a5)\">\n    <image xlink:href=\"data:image/png;base64,\[encoded data, 21845 characters]\" id=\"imageac8fb64279\" transform=\"scale(1 -1) translate(0 -72.72)\" x=\"180.372414\" y=\"-6.635172\" width=\"72.72\" height=\"72.72\"/>\n   </g>\n   <g id=\"patch_13\">\n    <path d=\"M 180.372414 79.355172 \nL 180.372414 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_14\">\n    <path d=\"M 252.527586 79.355172 \nL 252.527586 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_15\">\n    <path d=\"M 180.372414 79.355172 \nL 252.527586 79.355172 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_16\">\n    <path d=\"M 180.372414 7.2 \nL 252.527586 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n  </g>\n  <g id=\"axes_4\">\n   <g id=\"patch_17\">\n    <path d=\"M 266.958621 79.355172 \nL 339.113793 79.355172 \nL 339.113793 7.2 \nL 266.958621 7.2 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#p021d78f9f3)\">\n    <image xlink:href=\"data:image/png;base64,\[encoded data, 20361 characters]\" id=\"imaged641a08e58\" transform=\"scale(1 -1) translate(0 -72.72)\" x=\"266.958621\" y=\"-6.635172\" width=\"72.72\" height=\"72.72\"/>\n   </g>\n   <g id=\"patch_18\">\n    <path d=\"M 266.958621 79.355172 \nL 266.958621 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_19\">\n    <path d=\"M 339.113793 79.355172 \nL 339.113793 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_20\">\n    <path d=\"M 266.958621 79.355172 \nL 339.113793 79.355172 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_21\">\n    <path d=\"M 266.958621 7.2 \nL 339.113793 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n  </g>\n  <g id=\"axes_5\">\n   <g id=\"patch_22\">\n    <path d=\"M 353.544828 79.355172 \nL 425.7 79.355172 \nL 425.7 7.2 \nL 353.544828 7.2 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#p8930b4e9af)\">\n    <image xlink:href=\"data:image/png;base64,\[encoded data, 16793 characters]\" id=\"imagef37525bde1\" transform=\"scale(1 -1) translate(0 -72.72)\" x=\"353.544828\" y=\"-6.635172\" width=\"72.72\" height=\"72.72\"/>\n   </g>\n   <g id=\"patch_23\">\n    <path d=\"M 353.544828 79.355172 \nL 353.544828 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_24\">\n    <path d=\"M 425.7 79.355172 \nL 425.7 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_25\">\n    <path d=\"M 353.544828 79.355172 \nL 425.7 79.355172 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_26\">\n    <path d=\"M 353.544828 7.2 \nL 425.7 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n  </g>\n  <g id=\"axes_6\">\n   <g id=\"patch_27\">\n    <path d=\"M 7.2 166.130825 \nL 79.355172 166.130825 \nL 79.355172 93.975652 \nL 7.2 93.975652 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#pf9521d9516)\">\n    <image xlink:href=\"data:image/png;base64,\[encoded data, 13897 characters]\" id=\"image9f9fb23069\" transform=\"scale(1 -1) translate(0 -72.72)\" x=\"7.2\" y=\"-93.410825\" width=\"72.72\" height=\"72.72\"/>\n   </g>\n   <g id=\"patch_28\">\n    <path d=\"M 7.2 166.130825 \nL 7.2 93.975652 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_29\">\n    <path d=\"M 79.355172 166.130825 \nL 79.355172 93.975652 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_30\">\n    <path d=\"M 7.2 166.130825 \nL 79.355172 166.130825 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_31\">\n    <path d=\"M 7.2 93.975652 \nL 79.355172 93.975652 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n  </g>\n  <g id=\"axes_7\">\n   <g id=\"patch_32\">\n    <path d=\"M 93.786207 166.130825 \nL 165.941379 166.130825 \nL 165.941379 93.975652 \nL 93.786207 93.975652 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#pbff51b8aa5)\">\n    <image xlink:href=\"data:image/png;base64,\[encoded data, 18429 characters]\" id=\"image7c71caf468\" transform=\"scale(1 -1) translate(0 -72.72)\" x=\"93.786207\" y=\"-93.410825\" width=\"72.72\" height=\"72.72\"/>\n   </g>\n   <g id=\"patch_33\">\n    <path d=\"M 93.786207 166.130825 \nL 93.786207 93.975652 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_34\">\n    <path d=\"M 165.941379 166.130825 \nL 165.941379 93.975652 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_35\">\n    <path d=\"M 93.786207 166.130825 \nL 165.941379 166.130825 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_36\">\n    <path d=\"M 93.786207 93.975652 \nL 165.941379 93.975652 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n  </g>\n  <g id=\"axes_8\">\n   <g id=\"patch_37\">\n    <path d=\"M 180.372414 166.130825 \nL 252.527586 166.130825 \nL 252.527586 93.975652 \nL 180.372414 93.975652 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#pd3105e0420)\">\n    <image xlink:href=\"data:image/png;base64,\[encoded data, 19169 characters]\" id=\"image4cdf5f636d\" transform=\"scale(1 -1) translate(0 -72.72)\" x=\"180.372414\" y=\"-93.410825\" width=\"72.72\" height=\"72.72\"/>\n   </g>\n   <g id=\"patch_38\">\n    <path d=\"M 180.372414 166.130825 \nL 180.372414 93.975652 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_39\">\n    <path d=\"M 252.527586 166.130825 \nL 252.527586 93.975652 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_40\">\n    <path d=\"M 180.372414 166.130825 \nL 252.527586 166.130825 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_41\">\n    <path d=\"M 180.372414 93.975652 \nL 252.527586 93.975652 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n  </g>\n  <g id=\"axes_9\">\n   <g id=\"patch_42\">\n    <path d=\"M 266.958621 166.130825 \nL 339.113793 166.130825 \nL 339.113793 93.975652 \nL 266.958621 93.975652 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#p6181d4e3f7)\">\n    <image xlink:href=\"data:image/png;base64,\[encoded data, 17173 characters]\" id=\"image1200c740ee\" transform=\"scale(1 -1) translate(0 -72.72)\" x=\"266.958621\" y=\"-93.410825\" width=\"72.72\" height=\"72.72\"/>\n   </g>\n   <g id=\"patch_43\">\n    <path d=\"M 266.958621 166.130825 \nL 266.958621 93.975652 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_44\">\n    <path d=\"M 339.113793 166.130825 \nL 339.113793 93.975652 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_45\">\n    <path d=\"M 266.958621 166.130825 \nL 339.113793 166.130825 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_46\">\n    <path d=\"M 266.958621 93.975652 \nL 339.113793 93.975652 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n  </g>\n  <g id=\"axes_10\">\n   <g id=\"patch_47\">\n    <path d=\"M 353.544828 166.130825 \nL 425.7 166.130825 \nL 425.7 93.975652 \nL 353.544828 93.975652 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#p748fad0a3d)\">\n    <image xlink:href=\"data:image/png;base64,\[encoded data, 23177 characters]\" id=\"image1e88c10305\" transform=\"scale(1 -1) translate(0 -72.72)\" x=\"353.544828\" y=\"-93.410825\" width=\"72.72\" height=\"72.72\"/>\n   </g>\n   <g id=\"patch_48\">\n    <path d=\"M 353.544828 166.130825 \nL 353.544828 93.975652 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_49\">\n    <path d=\"M 425.7 166.130825 \nL 425.7 93.975652 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_50\">\n    <path d=\"M 353.544828 166.130825 \nL 425.7 166.130825 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_51\">\n    <path d=\"M 353.544828 93.975652 \nL 425.7 93.975652 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n  </g>\n  <g id=\"axes_11\">\n   <g id=\"patch_52\">\n    <path d=\"M 7.2 252.906477 \nL 79.355172 252.906477 \nL 79.355172 180.751304 \nL 7.2 180.751304 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#p7b3a6c6d7f)\">\n    <image xlink:href=\"data:image/png;base64,\[encoded data, 19489 characters]\" id=\"imageeb52f99f8a\" transform=\"scale(1 -1) translate(0 -72.72)\" x=\"7.2\" y=\"-180.186477\" width=\"72.72\" height=\"72.72\"/>\n   </g>\n   <g id=\"patch_53\">\n    <path d=\"M 7.2 252.906477 \nL 7.2 180.751304 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_54\">\n    <path d=\"M 79.355172 252.906477 \nL 79.355172 180.751304 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_55\">\n    <path d=\"M 7.2 252.906477 \nL 79.355172 252.906477 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_56\">\n    <path d=\"M 7.2 180.751304 \nL 79.355172 180.751304 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n  </g>\n  <g id=\"axes_12\">\n   <g id=\"patch_57\">\n    <path d=\"M 93.786207 252.906477 \nL 165.941379 252.906477 \nL 165.941379 180.751304 \nL 93.786207 180.751304 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#pb697f3da3e)\">\n    <image xlink:href=\"data:image/png;base64,\[encoded data, 14125 characters]\" id=\"image122fc43d6c\" transform=\"scale(1 -1) translate(0 -72.72)\" x=\"93.786207\" y=\"-180.186477\" width=\"72.72\" height=\"72.72\"/>\n   </g>\n   <g id=\"patch_58\">\n    <path d=\"M 93.786207 252.906477 \nL 93.786207 180.751304 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_59\">\n    <path d=\"M 165.941379 252.906477 \nL 165.941379 180.751304 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_60\">\n    <path d=\"M 93.786207 252.906477 \nL 165.941379 252.906477 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_61\">\n    <path d=\"M 93.786207 180.751304 \nL 165.941379 180.751304 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n  </g>\n  <g id=\"axes_13\">\n   <g id=\"patch_62\">\n    <path d=\"M 180.372414 252.906477 \nL 252.527586 252.906477 \nL 252.527586 180.751304 \nL 180.372414 180.751304 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#pad2e8d8d9f)\">\n    <image xlink:href=\"data:image/png;base64,\[encoded data, 20749 characters]\" id=\"image7df8e4f046\" transform=\"scale(1 -1) translate(0 -72.72)\" x=\"180.372414\" y=\"-180.186477\" width=\"72.72\" height=\"72.72\"/>\n   </g>\n   <g id=\"patch_63\">\n    <path d=\"M 180.372414 252.906477 \nL 180.372414 180.751304 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_64\">\n    <path d=\"M 252.527586 252.906477 \nL 252.527586 180.751304 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_65\">\n    <path d=\"M 180.372414 252.906477 \nL 252.527586 252.906477 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_66\">\n    <path d=\"M 180.372414 180.751304 \nL 252.527586 180.751304 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n  </g>\n  <g id=\"axes_14\">\n   <g id=\"patch_67\">\n    <path d=\"M 266.958621 252.906477 \nL 339.113793 252.906477 \nL 339.113793 180.751304 \nL 266.958621 180.751304 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#p4975c041bb)\">\n    <image xlink:href=\"data:image/png;base64,\[encoded data, 15697 characters]\" id=\"image27008d708c\" transform=\"scale(1 -1) translate(0 -72.72)\" x=\"266.958621\" y=\"-180.186477\" width=\"72.72\" height=\"72.72\"/>\n   </g>\n   <g id=\"patch_68\">\n    <path d=\"M 266.958621 252.906477 \nL 266.958621 180.751304 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_69\">\n    <path d=\"M 339.113793 252.906477 \nL 339.113793 180.751304 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_70\">\n    <path d=\"M 266.958621 252.906477 \nL 339.113793 252.906477 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_71\">\n    <path d=\"M 266.958621 180.751304 \nL 339.113793 180.751304 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n  </g>\n  <g id=\"axes_15\">\n   <g id=\"patch_72\">\n    <path d=\"M 353.544828 252.906477 \nL 425.7 252.906477 \nL 425.7 180.751304 \nL 353.544828 180.751304 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#p7bf8ef3dc5)\">\n    <image xlink:href=\"data:image/png;base64,\[encoded data, 18973 characters]\" id=\"image48343a4e04\" transform=\"scale(1 -1) translate(0 -72.72)\" x=\"353.544828\" y=\"-180.186477\" width=\"72.72\" height=\"72.72\"/>\n   </g>\n   <g id=\"patch_73\">\n    <path d=\"M 353.544828 252.906477 \nL 353.544828 180.751304 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_74\">\n    <path d=\"M 425.7 252.906477 \nL 425.7 180.751304 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_75\">\n    <path d=\"M 353.544828 252.906477 \nL 425.7 252.906477 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_76\">\n    <path d=\"M 353.544828 180.751304 \nL 425.7 180.751304 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n  </g>\n  <g id=\"axes_16\">\n   <g id=\"patch_77\">\n    <path d=\"M 7.2 339.682129 \nL 79.355172 339.682129 \nL 79.355172 267.526957 \nL 7.2 267.526957 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#p8d9eded8e4)\">\n    <image xlink:href=\"data:image/png;base64,\[encoded data, 17129 characters]\" id=\"image89906f7e23\" transform=\"scale(1 -1) translate(0 -72.72)\" x=\"7.2\" y=\"-266.962129\" width=\"72.72\" height=\"72.72\"/>\n   </g>\n   <g id=\"patch_78\">\n    <path d=\"M 7.2 339.682129 \nL 7.2 267.526957 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_79\">\n    <path d=\"M 79.355172 339.682129 \nL 79.355172 267.526957 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_80\">\n    <path d=\"M 7.2 339.682129 \nL 79.355172 339.682129 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_81\">\n    <path d=\"M 7.2 267.526957 \nL 79.355172 267.526957 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n  </g>\n  <g id=\"axes_17\">\n   <g id=\"patch_82\">\n    <path d=\"M 93.786207 339.682129 \nL 165.941379 339.682129 \nL 165.941379 267.526957 \nL 93.786207 267.526957 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#p2795c264f4)\">\n    <image xlink:href=\"data:image/png;base64,\[encoded data, 17605 characters]\" id=\"image8d543eaa3c\" transform=\"scale(1 -1) translate(0 -72.72)\" x=\"93.786207\" y=\"-266.962129\" width=\"72.72\" height=\"72.72\"/>\n   </g>\n   <g id=\"patch_83\">\n    <path d=\"M 93.786207 339.682129 \nL 93.786207 267.526957 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_84\">\n    <path d=\"M 165.941379 339.682129 \nL 165.941379 267.526957 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_85\">\n    <path d=\"M 93.786207 339.682129 \nL 165.941379 339.682129 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_86\">\n    <path d=\"M 93.786207 267.526957 \nL 165.941379 267.526957 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n  </g>\n  <g id=\"axes_18\">\n   <g id=\"patch_87\">\n    <path d=\"M 180.372414 339.682129 \nL 252.527586 339.682129 \nL 252.527586 267.526957 \nL 180.372414 267.526957 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#p28283ad7f1)\">\n    <image xlink:href=\"data:image/png;base64,\[encoded data, 18901 characters]\" id=\"imageb1c273d901\" transform=\"scale(1 -1) translate(0 -72.72)\" x=\"180.372414\" y=\"-266.962129\" width=\"72.72\" height=\"72.72\"/>\n   </g>\n   <g id=\"patch_88\">\n    <path d=\"M 180.372414 339.682129 \nL 180.372414 267.526957 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_89\">\n    <path d=\"M 252.527586 339.682129 \nL 252.527586 267.526957 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_90\">\n    <path d=\"M 180.372414 339.682129 \nL 252.527586 339.682129 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_91\">\n    <path d=\"M 180.372414 267.526957 \nL 252.527586 267.526957 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n  </g>\n  <g id=\"axes_19\">\n   <g id=\"patch_92\">\n    <path d=\"M 266.958621 339.682129 \nL 339.113793 339.682129 \nL 339.113793 267.526957 \nL 266.958621 267.526957 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#pb38370db1c)\">\n    <image xlink:href=\"data:image/png;base64,\[encoded data, 18089 characters]\" id=\"imagea1c271aa9d\" transform=\"scale(1 -1) translate(0 -72.72)\" x=\"266.958621\" y=\"-266.962129\" width=\"72.72\" height=\"72.72\"/>\n   </g>\n   <g id=\"patch_93\">\n    <path d=\"M 266.958621 339.682129 \nL 266.958621 267.526957 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_94\">\n    <path d=\"M 339.113793 339.682129 \nL 339.113793 267.526957 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_95\">\n    <path d=\"M 266.958621 339.682129 \nL 339.113793 339.682129 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_96\">\n    <path d=\"M 266.958621 267.526957 \nL 339.113793 267.526957 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n  </g>\n  <g id=\"axes_20\">\n   <g id=\"patch_97\">\n    <path d=\"M 353.544828 339.682129 \nL 425.7 339.682129 \nL 425.7 267.526957 \nL 353.544828 267.526957 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#pc17ffb0a66)\">\n    <image xlink:href=\"data:image/png;base64,\[encoded data, 21829 characters]\" id=\"image6545c8b8a1\" transform=\"scale(1 -1) translate(0 -72.72)\" x=\"353.544828\" y=\"-266.962129\" width=\"72.72\" height=\"72.72\"/>\n   </g>\n   <g id=\"patch_98\">\n    <path d=\"M 353.544828 339.682129 \nL 353.544828 267.526957 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_99\">\n    <path d=\"M 425.7 339.682129 \nL 425.7 267.526957 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_100\">\n    <path d=\"M 353.544828 339.682129 \nL 425.7 339.682129 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_101\">\n    <path d=\"M 353.544828 267.526957 \nL 425.7 267.526957 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n  </g>\n </g>\n <defs>\n  <clipPath id=\"pd5d609d1eb\">\n   <rect x=\"7.2\" y=\"7.2\" width=\"72.155172\" height=\"72.155172\"/>\n  </clipPath>\n  <clipPath id=\"pc9c75718df\">\n   <rect x=\"93.786207\" y=\"7.2\" width=\"72.155172\" height=\"72.155172\"/>\n  </clipPath>\n  <clipPath id=\"pa834f822a5\">\n   <rect x=\"180.372414\" y=\"7.2\" width=\"72.155172\" height=\"72.155172\"/>\n  </clipPath>\n  <clipPath id=\"p021d78f9f3\">\n   <rect x=\"266.958621\" y=\"7.2\" width=\"72.155172\" height=\"72.155172\"/>\n  </clipPath>\n  <clipPath id=\"p8930b4e9af\">\n   <rect x=\"353.544828\" y=\"7.2\" width=\"72.155172\" height=\"72.155172\"/>\n  </clipPath>\n  <clipPath id=\"pf9521d9516\">\n   <rect x=\"7.2\" y=\"93.975652\" width=\"72.155172\" height=\"72.155172\"/>\n  </clipPath>\n  <clipPath id=\"pbff51b8aa5\">\n   <rect x=\"93.786207\" y=\"93.975652\" width=\"72.155172\" height=\"72.155172\"/>\n  </clipPath>\n  <clipPath id=\"pd3105e0420\">\n   <rect x=\"180.372414\" y=\"93.975652\" width=\"72.155172\" height=\"72.155172\"/>\n  </clipPath>\n  <clipPath id=\"p6181d4e3f7\">\n   <rect x=\"266.958621\" y=\"93.975652\" width=\"72.155172\" height=\"72.155172\"/>\n  </clipPath>\n  <clipPath id=\"p748fad0a3d\">\n   <rect x=\"353.544828\" y=\"93.975652\" width=\"72.155172\" height=\"72.155172\"/>\n  </clipPath>\n  <clipPath id=\"p7b3a6c6d7f\">\n   <rect x=\"7.2\" y=\"180.751304\" width=\"72.155172\" height=\"72.155172\"/>\n  </clipPath>\n  <clipPath id=\"pb697f3da3e\">\n   <rect x=\"93.786207\" y=\"180.751304\" width=\"72.155172\" height=\"72.155172\"/>\n  </clipPath>\n  <clipPath id=\"pad2e8d8d9f\">\n   <rect x=\"180.372414\" y=\"180.751304\" width=\"72.155172\" height=\"72.155172\"/>\n  </clipPath>\n  <clipPath id=\"p4975c041bb\">\n   <rect x=\"266.958621\" y=\"180.751304\" width=\"72.155172\" height=\"72.155172\"/>\n  </clipPath>\n  <clipPath id=\"p7bf8ef3dc5\">\n   <rect x=\"353.544828\" y=\"180.751304\" width=\"72.155172\" height=\"72.155172\"/>\n  </clipPath>\n  <clipPath id=\"p8d9eded8e4\">\n   <rect x=\"7.2\" y=\"267.526957\" width=\"72.155172\" height=\"72.155172\"/>\n  </clipPath>\n  <clipPath id=\"p2795c264f4\">\n   <rect x=\"93.786207\" y=\"267.526957\" width=\"72.155172\" height=\"72.155172\"/>\n  </clipPath>\n  <clipPath id=\"p28283ad7f1\">\n   <rect x=\"180.372414\" y=\"267.526957\" width=\"72.155172\" height=\"72.155172\"/>\n  </clipPath>\n  <clipPath id=\"pb38370db1c\">\n   <rect x=\"266.958621\" y=\"267.526957\" width=\"72.155172\" height=\"72.155172\"/>\n  </clipPath>\n  <clipPath id=\"pc17ffb0a66\">\n   <rect x=\"353.544828\" y=\"267.526957\" width=\"72.155172\" height=\"72.155172\"/>\n  </clipPath>\n </defs>\n</svg>\n"
     },
     "metadata": {}
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=dcgan-md-5 fw=all -->\n",
    "\n",
    "## The Generator\n",
    "\n",
    "The generator needs to map the noise variable $\\mathbf z\\in\\mathbb R^d$, a length-$d$ vector, to an RGB image with width and height of $64\\times 64$ . In that section we introduced the fully convolutional network that uses transposed convolution layer (refer to that section) to enlarge input size. The basic block of the generator contains a transposed convolution layer followed by the batch normalization and ReLU activation."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "dcgan-the-generator-1"
   },
   "source": [
    "class G_block(nn.Block):\n",
    "    def __init__(self, channels, kernel_size=4,\n",
    "                 strides=2, padding=1):\n",
    "        super().__init__()\n",
    "        self.conv2d_trans = nn.Conv2DTranspose(\n",
    "            channels, kernel_size, strides, padding, use_bias=False)\n",
    "        self.batch_norm = nn.BatchNorm()\n",
    "        self.activation = nn.Activation('relu')\n",
    "\n",
    "    def forward(self, X):\n",
    "        return self.activation(self.batch_norm(self.conv2d_trans(X)))"
   ],
   "execution_count": 5,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=dcgan-md-6 fw=all -->\n",
    "\n",
    "In default, the transposed convolution layer uses a $k_h = k_w = 4$ kernel, a $s_h = s_w = 2$ strides, and a $p_h = p_w = 1$ padding. With an input shape of $n_h^{'} \\times n_w^{'} = 16 \\times 16$, the generator block will double input's width and height.\n",
    "\n",
    "$$\n",
    "\\begin{aligned}\n",
    "n_h^{'} \\times n_w^{'} &= [(n_h k_h - (n_h-1)(k_h-s_h)- 2p_h] \\times [(n_w k_w - (n_w-1)(k_w-s_w)- 2p_w]\\\\\n",
    "  &= [(k_h + s_h (n_h-1)- 2p_h] \\times [(k_w + s_w (n_w-1)- 2p_w]\\\\\n",
    "  &= [(4 + 2 \\times (16-1)- 2 \\times 1] \\times [(4 + 2 \\times (16-1)- 2 \\times 1]\\\\\n",
    "  &= 32 \\times 32 .\\\\\n",
    "\\end{aligned}\n",
    "$$"
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "dcgan-the-generator-2"
   },
   "source": [
    "x = np.zeros((2, 3, 16, 16))\n",
    "g_blk = G_block(20)\n",
    "g_blk.initialize()\n",
    "g_blk(x).shape"
   ],
   "execution_count": 6,
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "(2, 20, 32, 32)"
     },
     "metadata": {},
     "execution_count": 6
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=dcgan-md-7 fw=all -->\n",
    "\n",
    "If we change the transposed convolution layer to a $4\\times 4$ kernel, $1\\times 1$ strides and zero padding, then with an input size of $1 \\times 1$, the output will have its width and height increased by 3 respectively."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "dcgan-the-generator-3"
   },
   "source": [
    "x = np.zeros((2, 3, 1, 1))\n",
    "g_blk = G_block(20, strides=1, padding=0)\n",
    "g_blk.initialize()\n",
    "g_blk(x).shape"
   ],
   "execution_count": 7,
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "(2, 20, 4, 4)"
     },
     "metadata": {},
     "execution_count": 7
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=dcgan-md-8 fw=all -->\n",
    "\n",
    "The generator consists of four basic blocks that increase input's both width and height from 1 to 32. At the same time, it first projects the latent variable into $64\\times 8$ channels, and then halve the channels each time. At last, a transposed convolution layer is used to generate the output. It further doubles the width and height to match the desired $64\\times 64$ shape, and reduces the channel size to $3$. The tanh activation function is applied to project output values into the $(-1, 1)$ range."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "dcgan-the-generator-4"
   },
   "source": [
    "n_G = 64\n",
    "net_G = nn.Sequential()\n",
    "net_G.add(G_block(n_G*8, strides=1, padding=0),  # Output: (64 * 8, 4, 4)\n",
    "          G_block(n_G*4),  # Output: (64 * 4, 8, 8)\n",
    "          G_block(n_G*2),  # Output: (64 * 2, 16, 16)\n",
    "          G_block(n_G),    # Output: (64, 32, 32)\n",
    "          nn.Conv2DTranspose(\n",
    "              3, kernel_size=4, strides=2, padding=1, use_bias=False,\n",
    "              activation='tanh'))  # Output: (3, 64, 64)"
   ],
   "execution_count": 8,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=dcgan-md-9 fw=all -->\n",
    "\n",
    "Generate a 100 dimensional latent variable to verify the generator's output shape."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "dcgan-the-generator-5"
   },
   "source": [
    "x = np.zeros((1, 100, 1, 1))\n",
    "net_G.initialize()\n",
    "net_G(x).shape"
   ],
   "execution_count": 9,
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "(1, 3, 64, 64)"
     },
     "metadata": {},
     "execution_count": 9
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=dcgan-md-10 fw=all -->\n",
    "\n",
    "## Discriminator\n",
    "\n",
    "The discriminator is a normal convolutional network except that it uses a leaky ReLU as its activation function. Given $\\alpha \\in[0, 1]$, its definition is\n",
    "\n",
    "$$\\textrm{leaky ReLU}(x) = \\begin{cases}x & \\textrm{if}\\ x > 0\\\\ \\alpha x &\\textrm{otherwise}\\end{cases}.$$\n",
    "\n",
    "As it can be seen, it is normal ReLU if $\\alpha=0$, and an identity function if $\\alpha=1$. For $\\alpha \\in (0, 1)$, leaky ReLU is a nonlinear function that give a non-zero output for a negative input. It aims to fix the \"dying ReLU\" problem that a neuron might always output a negative value and therefore cannot make any progress since the gradient of ReLU is 0."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "dcgan-discriminator-1"
   },
   "source": [
    "alphas = [0, .2, .4, .6, .8, 1]\n",
    "x = d2l.arange(-2, 1, 0.1)\n",
    "Y = [d2l.numpy(nn.LeakyReLU(alpha)(x)) for alpha in alphas]\n",
    "d2l.plot(d2l.numpy(x), Y, 'x', 'y', alphas)"
   ],
   "execution_count": 10,
   "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=\"255.087166pt\" height=\"186.855463pt\" viewBox=\"0 0 255.087166 186.855463\" 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-19T15:26:53.166074</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 186.855463 \nL 255.087166 186.855463 \nL 255.087166 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 52.160938 149.299213 \nL 247.460938 149.299213 \nL 247.460938 10.699213 \nL 52.160938 10.699213 \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 d=\"M 61.03821 149.299213 \nL 61.03821 10.699213 \n\" clip-path=\"url(#p025b67e7fd)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_2\">\n      <defs>\n       <path id=\"mfec98d9604\" d=\"M 0 0 \nL 0 3.5 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#mfec98d9604\" x=\"61.03821\" y=\"149.299213\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_1\">\n      <!-- −2 -->\n      <g transform=\"translate(53.667116 163.89765) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-2212\" d=\"M 678 2272 \nL 4684 2272 \nL 4684 1741 \nL 678 1741 \nL 678 2272 \nz\n\" transform=\"scale(0.015625)\"/>\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-2212\"/>\n       <use xlink:href=\"#DejaVuSans-32\" transform=\"translate(83.789062 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_2\">\n     <g id=\"line2d_3\">\n      <path d=\"M 122.260779 149.299213 \nL 122.260779 10.699213 \n\" clip-path=\"url(#p025b67e7fd)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_4\">\n      <g>\n       <use xlink:href=\"#mfec98d9604\" x=\"122.260779\" y=\"149.299213\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_2\">\n      <!-- −1 -->\n      <g transform=\"translate(114.889685 163.89765) 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-2212\"/>\n       <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(83.789062 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_3\">\n     <g id=\"line2d_5\">\n      <path d=\"M 183.483347 149.299213 \nL 183.483347 10.699213 \n\" clip-path=\"url(#p025b67e7fd)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_6\">\n      <g>\n       <use xlink:href=\"#mfec98d9604\" x=\"183.483347\" y=\"149.299213\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_3\">\n      <!-- 0 -->\n      <g transform=\"translate(180.302097 163.89765) 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_4\">\n     <g id=\"line2d_7\">\n      <path d=\"M 244.705916 149.299213 \nL 244.705916 10.699213 \n\" clip-path=\"url(#p025b67e7fd)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_8\">\n      <g>\n       <use xlink:href=\"#mfec98d9604\" x=\"244.705916\" y=\"149.299213\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_4\">\n      <!-- 1 -->\n      <g transform=\"translate(241.524666 163.89765) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-31\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"text_5\">\n     <!-- x -->\n     <g transform=\"translate(146.851563 177.575775) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"DejaVuSans-78\" d=\"M 3513 3500 \nL 2247 1797 \nL 3578 0 \nL 2900 0 \nL 1881 1375 \nL 863 0 \nL 184 0 \nL 1544 1831 \nL 300 3500 \nL 978 3500 \nL 1906 2253 \nL 2834 3500 \nL 3513 3500 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#DejaVuSans-78\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"matplotlib.axis_2\">\n    <g id=\"ytick_1\">\n     <g id=\"line2d_9\">\n      <path d=\"M 52.160938 130.999211 \nL 247.460938 130.999211 \n\" clip-path=\"url(#p025b67e7fd)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_10\">\n      <defs>\n       <path id=\"m6d1f7a79da\" d=\"M 0 0 \nL -3.5 0 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#m6d1f7a79da\" x=\"52.160938\" y=\"130.999211\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_6\">\n      <!-- −1.0 -->\n      <g transform=\"translate(20.878125 134.798429) 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       </defs>\n       <use xlink:href=\"#DejaVuSans-2212\"/>\n       <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(83.789062 0)\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(147.412109 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(179.199219 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_2\">\n     <g id=\"line2d_11\">\n      <path d=\"M 52.160938 100.999213 \nL 247.460938 100.999213 \n\" clip-path=\"url(#p025b67e7fd)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_12\">\n      <g>\n       <use xlink:href=\"#m6d1f7a79da\" x=\"52.160938\" y=\"100.999213\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_7\">\n      <!-- −0.5 -->\n      <g transform=\"translate(20.878125 104.798431) scale(0.1 -0.1)\">\n       <defs>\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-2212\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(83.789062 0)\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(147.412109 0)\"/>\n       <use xlink:href=\"#DejaVuSans-35\" transform=\"translate(179.199219 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_3\">\n     <g id=\"line2d_13\">\n      <path d=\"M 52.160938 70.999215 \nL 247.460938 70.999215 \n\" clip-path=\"url(#p025b67e7fd)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_14\">\n      <g>\n       <use xlink:href=\"#m6d1f7a79da\" x=\"52.160938\" y=\"70.999215\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_8\">\n      <!-- 0.0 -->\n      <g transform=\"translate(29.257812 74.798433) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\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_4\">\n     <g id=\"line2d_15\">\n      <path d=\"M 52.160938 40.999217 \nL 247.460938 40.999217 \n\" clip-path=\"url(#p025b67e7fd)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_16\">\n      <g>\n       <use xlink:href=\"#m6d1f7a79da\" x=\"52.160938\" y=\"40.999217\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_9\">\n      <!-- 0.5 -->\n      <g transform=\"translate(29.257812 44.798435) scale(0.1 -0.1)\">\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_5\">\n     <g id=\"line2d_17\">\n      <path d=\"M 52.160938 10.999219 \nL 247.460938 10.999219 \n\" clip-path=\"url(#p025b67e7fd)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_18\">\n      <g>\n       <use xlink:href=\"#m6d1f7a79da\" x=\"52.160938\" y=\"10.999219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_10\">\n      <!-- 1.0 -->\n      <g transform=\"translate(29.257812 14.798438) 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=\"text_11\">\n     <!-- y -->\n     <g transform=\"translate(14.798438 82.958588) rotate(-90) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"DejaVuSans-79\" d=\"M 2059 -325 \nQ 1816 -950 1584 -1140 \nQ 1353 -1331 966 -1331 \nL 506 -1331 \nL 506 -850 \nL 844 -850 \nQ 1081 -850 1212 -737 \nQ 1344 -625 1503 -206 \nL 1606 56 \nL 191 3500 \nL 800 3500 \nL 1894 763 \nL 2988 3500 \nL 3597 3500 \nL 2059 -325 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#DejaVuSans-79\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"line2d_19\">\n    <path d=\"M 61.03821 70.999215 \nL 67.160469 70.999215 \nL 73.282727 70.999215 \nL 79.404978 70.999215 \nL 85.527236 70.999215 \nL 91.649494 70.999215 \nL 97.771753 70.999215 \nL 103.894011 70.999215 \nL 110.016262 70.999215 \nL 116.138528 70.999215 \nL 122.260779 70.999215 \nL 128.383037 70.999215 \nL 134.505295 70.999215 \nL 140.627554 70.999215 \nL 146.749805 70.999215 \nL 152.872063 70.999215 \nL 158.994321 70.999215 \nL 165.11658 70.999215 \nL 171.238838 70.999215 \nL 177.361089 70.999215 \nL 183.483347 70.999215 \nL 189.605613 64.999206 \nL 195.727864 58.999213 \nL 201.850115 52.999219 \nL 207.972381 46.999211 \nL 214.094632 40.999217 \nL 220.216897 34.999209 \nL 226.339148 28.999215 \nL 232.461399 22.999221 \nL 238.583665 16.999213 \n\" clip-path=\"url(#p025b67e7fd)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n   </g>\n   <g id=\"line2d_20\">\n    <path d=\"M 61.03821 94.999213 \nL 67.160469 93.799213 \nL 73.282727 92.599212 \nL 79.404978 91.399213 \nL 85.527236 90.199215 \nL 91.649494 88.999214 \nL 97.771753 87.799214 \nL 103.894011 86.599213 \nL 110.016262 85.399214 \nL 116.138528 84.199213 \nL 122.260779 82.999214 \nL 128.383037 81.799213 \nL 134.505295 80.599214 \nL 140.627554 79.399213 \nL 146.749805 78.199214 \nL 152.872063 76.999214 \nL 158.994321 75.799214 \nL 165.11658 74.599214 \nL 171.238838 73.399214 \nL 177.361089 72.199215 \nL 183.483347 70.999215 \nL 189.605613 64.999206 \nL 195.727864 58.999213 \nL 201.850115 52.999219 \nL 207.972381 46.999211 \nL 214.094632 40.999217 \nL 220.216897 34.999209 \nL 226.339148 28.999215 \nL 232.461399 22.999221 \nL 238.583665 16.999213 \n\" clip-path=\"url(#p025b67e7fd)\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #bf00bf; stroke-width: 1.5\"/>\n   </g>\n   <g id=\"line2d_21\">\n    <path d=\"M 61.03821 118.999212 \nL 67.160469 116.599211 \nL 73.282727 114.19921 \nL 79.404978 111.799212 \nL 85.527236 109.399215 \nL 91.649494 106.999214 \nL 97.771753 104.599213 \nL 103.894011 102.199211 \nL 110.016262 99.799214 \nL 116.138528 97.399211 \nL 122.260779 94.999213 \nL 128.383037 92.599212 \nL 134.505295 90.199213 \nL 140.627554 87.799212 \nL 146.749805 85.399214 \nL 152.872063 82.999214 \nL 158.994321 80.599214 \nL 165.11658 78.199213 \nL 171.238838 75.799213 \nL 177.361089 73.399215 \nL 183.483347 70.999215 \nL 189.605613 64.999206 \nL 195.727864 58.999213 \nL 201.850115 52.999219 \nL 207.972381 46.999211 \nL 214.094632 40.999217 \nL 220.216897 34.999209 \nL 226.339148 28.999215 \nL 232.461399 22.999221 \nL 238.583665 16.999213 \n\" clip-path=\"url(#p025b67e7fd)\" style=\"fill: none; stroke-dasharray: 9.6,2.4,1.5,2.4; stroke-dashoffset: 0; stroke: #008000; stroke-width: 1.5\"/>\n   </g>\n   <g id=\"line2d_22\">\n    <path d=\"M 61.03821 142.999213 \nL 67.160469 139.399209 \nL 73.282727 135.799213 \nL 79.404978 132.199217 \nL 85.527236 128.599213 \nL 91.649494 124.999213 \nL 97.771753 121.399213 \nL 103.894011 117.799213 \nL 110.016262 114.199213 \nL 116.138528 110.59921 \nL 122.260779 106.999214 \nL 128.383037 103.399214 \nL 134.505295 99.799212 \nL 140.627554 96.199212 \nL 146.749805 92.599214 \nL 152.872063 88.999214 \nL 158.994321 85.399213 \nL 165.11658 81.799213 \nL 171.238838 78.199212 \nL 177.361089 74.599215 \nL 183.483347 70.999215 \nL 189.605613 64.999206 \nL 195.727864 58.999213 \nL 201.850115 52.999219 \nL 207.972381 46.999211 \nL 214.094632 40.999217 \nL 220.216897 34.999209 \nL 226.339148 28.999215 \nL 232.461399 22.999221 \nL 238.583665 16.999213 \n\" clip-path=\"url(#p025b67e7fd)\" style=\"fill: none; stroke-dasharray: 1.5,2.475; stroke-dashoffset: 0; stroke: #ff0000; stroke-width: 1.5\"/>\n   </g>\n   <g id=\"patch_3\">\n    <path d=\"M 52.160938 149.299213 \nL 52.160938 10.699213 \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 247.460938 149.299213 \nL 247.460938 10.699213 \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 52.160937 149.299213 \nL 247.460938 149.299213 \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 52.160937 10.699213 \nL 247.460938 10.699213 \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 192.557813 144.299213 \nL 240.460938 144.299213 \nQ 242.460938 144.299213 242.460938 142.299213 \nL 242.460938 84.586713 \nQ 242.460938 82.586713 240.460938 82.586713 \nL 192.557813 82.586713 \nQ 190.557813 82.586713 190.557813 84.586713 \nL 190.557813 142.299213 \nQ 190.557813 144.299213 192.557813 144.299213 \nz\n\" style=\"fill: #ffffff; opacity: 0.8; stroke: #cccccc; stroke-linejoin: miter\"/>\n    </g>\n    <g id=\"line2d_23\">\n     <path d=\"M 194.557813 90.68515 \nL 204.557813 90.68515 \nL 214.557813 90.68515 \n\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n    </g>\n    <g id=\"text_12\">\n     <!-- 0 -->\n     <g transform=\"translate(222.557813 94.18515) scale(0.1 -0.1)\">\n      <use xlink:href=\"#DejaVuSans-30\"/>\n     </g>\n    </g>\n    <g id=\"line2d_24\">\n     <path d=\"M 194.557813 105.363275 \nL 204.557813 105.363275 \nL 214.557813 105.363275 \n\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #bf00bf; stroke-width: 1.5\"/>\n    </g>\n    <g id=\"text_13\">\n     <!-- 0.2 -->\n     <g transform=\"translate(222.557813 108.863275) scale(0.1 -0.1)\">\n      <use xlink:href=\"#DejaVuSans-30\"/>\n      <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0)\"/>\n      <use xlink:href=\"#DejaVuSans-32\" transform=\"translate(95.410156 0)\"/>\n     </g>\n    </g>\n    <g id=\"line2d_25\">\n     <path d=\"M 194.557813 120.0414 \nL 204.557813 120.0414 \nL 214.557813 120.0414 \n\" style=\"fill: none; stroke-dasharray: 9.6,2.4,1.5,2.4; stroke-dashoffset: 0; stroke: #008000; stroke-width: 1.5\"/>\n    </g>\n    <g id=\"text_14\">\n     <!-- 0.4 -->\n     <g transform=\"translate(222.557813 123.5414) 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-30\"/>\n      <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0)\"/>\n      <use xlink:href=\"#DejaVuSans-34\" transform=\"translate(95.410156 0)\"/>\n     </g>\n    </g>\n    <g id=\"line2d_26\">\n     <path d=\"M 194.557813 134.719525 \nL 204.557813 134.719525 \nL 214.557813 134.719525 \n\" style=\"fill: none; stroke-dasharray: 1.5,2.475; stroke-dashoffset: 0; stroke: #ff0000; stroke-width: 1.5\"/>\n    </g>\n    <g id=\"text_15\">\n     <!-- 0.6 -->\n     <g transform=\"translate(222.557813 138.219525) 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-30\"/>\n      <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0)\"/>\n      <use xlink:href=\"#DejaVuSans-36\" transform=\"translate(95.410156 0)\"/>\n     </g>\n    </g>\n   </g>\n  </g>\n </g>\n <defs>\n  <clipPath id=\"p025b67e7fd\">\n   <rect x=\"52.160938\" y=\"10.699213\" width=\"195.3\" height=\"138.6\"/>\n  </clipPath>\n </defs>\n</svg>\n"
     },
     "metadata": {}
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=dcgan-md-11 fw=all -->\n",
    "\n",
    "The basic block of the discriminator is a convolution layer followed by a batch normalization layer and a leaky ReLU activation. The hyperparameters of the convolution layer are similar to the transpose convolution layer in the generator block."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "dcgan-discriminator-2"
   },
   "source": [
    "class D_block(nn.Block):\n",
    "    def __init__(self, channels, kernel_size=4, strides=2,\n",
    "                 padding=1, alpha=0.2):\n",
    "        super().__init__()\n",
    "        self.conv2d = nn.Conv2D(\n",
    "            channels, kernel_size, strides, padding, use_bias=False)\n",
    "        self.batch_norm = nn.BatchNorm()\n",
    "        self.activation = nn.LeakyReLU(alpha)\n",
    "\n",
    "    def forward(self, X):\n",
    "        return self.activation(self.batch_norm(self.conv2d(X)))"
   ],
   "execution_count": 11,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=dcgan-md-12 fw=all -->\n",
    "\n",
    "A basic block with default settings will halve the width and height of the inputs, as we demonstrated in that section. For example, given a input shape $n_h = n_w = 16$, with a kernel shape $k_h = k_w = 4$, a stride shape $s_h = s_w = 2$, and a padding shape $p_h = p_w = 1$, the output shape will be:\n",
    "\n",
    "$$\n",
    "\\begin{aligned}\n",
    "n_h^{'} \\times n_w^{'} &= \\lfloor(n_h-k_h+2p_h+s_h)/s_h\\rfloor \\times \\lfloor(n_w-k_w+2p_w+s_w)/s_w\\rfloor\\\\\n",
    "  &= \\lfloor(16-4+2\\times 1+2)/2\\rfloor \\times \\lfloor(16-4+2\\times 1+2)/2\\rfloor\\\\\n",
    "  &= 8 \\times 8 .\\\\\n",
    "\\end{aligned}\n",
    "$$"
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "dcgan-discriminator-3"
   },
   "source": [
    "x = np.zeros((2, 3, 16, 16))\n",
    "d_blk = D_block(20)\n",
    "d_blk.initialize()\n",
    "d_blk(x).shape"
   ],
   "execution_count": 12,
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "(2, 20, 8, 8)"
     },
     "metadata": {},
     "execution_count": 12
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=dcgan-md-13 fw=all -->\n",
    "\n",
    "The discriminator is a mirror of the generator."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "dcgan-discriminator-4"
   },
   "source": [
    "n_D = 64\n",
    "net_D = nn.Sequential()\n",
    "net_D.add(D_block(n_D),   # Output: (64, 32, 32)\n",
    "          D_block(n_D*2),  # Output: (64 * 2, 16, 16)\n",
    "          D_block(n_D*4),  # Output: (64 * 4, 8, 8)\n",
    "          D_block(n_D*8),  # Output: (64 * 8, 4, 4)\n",
    "          nn.Conv2D(1, kernel_size=4, use_bias=False))  # Output: (1, 1, 1)"
   ],
   "execution_count": 13,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=dcgan-md-14 fw=all -->\n",
    "\n",
    "It uses a convolution layer with output channel $1$ as the last layer to obtain a single prediction value."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "dcgan-discriminator-5"
   },
   "source": [
    "x = np.zeros((1, 3, 64, 64))\n",
    "net_D.initialize()\n",
    "net_D(x).shape"
   ],
   "execution_count": 14,
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "(1, 1, 1, 1)"
     },
     "metadata": {},
     "execution_count": 14
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=dcgan-md-15 fw=all -->\n",
    "\n",
    "## Training\n",
    "\n",
    "Compared to the basic GAN in that section, we use the same learning rate for both generator and discriminator since they are similar to each other. In addition, we change $\\beta_1$ in Adam (that section) from $0.9$ to $0.5$. It decreases the smoothness of the momentum, the exponentially weighted moving average of past gradients, to take care of the rapid changing gradients because the generator and the discriminator fight with each other. Besides, the random generated noise `Z`, is a 4-D tensor and we are using GPU to accelerate the computation."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "dcgan-training-1"
   },
   "source": [
    "def train(net_D, net_G, data_iter, num_epochs, lr, latent_dim,\n",
    "          device=d2l.try_gpu()):\n",
    "    loss = gluon.loss.SigmoidBCELoss()\n",
    "    net_D.initialize(init=init.Normal(0.02), force_reinit=True, ctx=device)\n",
    "    net_G.initialize(init=init.Normal(0.02), force_reinit=True, ctx=device)\n",
    "    trainer_hp = {'learning_rate': lr, 'beta1': 0.5}\n",
    "    trainer_D = gluon.Trainer(net_D.collect_params(), 'adam', trainer_hp)\n",
    "    trainer_G = gluon.Trainer(net_G.collect_params(), 'adam', trainer_hp)\n",
    "    animator = d2l.Animator(xlabel='epoch', ylabel='loss',\n",
    "                            xlim=[1, num_epochs], nrows=2, figsize=(5, 5),\n",
    "                            legend=['discriminator', 'generator'])\n",
    "    animator.fig.subplots_adjust(hspace=0.3)\n",
    "    for epoch in range(1, num_epochs + 1):\n",
    "        # Train one epoch\n",
    "        timer = d2l.Timer()\n",
    "        metric = d2l.Accumulator(3)  # loss_D, loss_G, num_examples\n",
    "        for X, _ in data_iter:\n",
    "            batch_size = X.shape[0]\n",
    "            Z = np.random.normal(0, 1, size=(batch_size, latent_dim, 1, 1))\n",
    "            X, Z = X.as_in_ctx(device), Z.as_in_ctx(device),\n",
    "            metric.add(d2l.update_D(X, Z, net_D, net_G, loss, trainer_D),\n",
    "                       d2l.update_G(Z, net_D, net_G, loss, trainer_G),\n",
    "                       batch_size)\n",
    "        # Show generated examples\n",
    "        Z = np.random.normal(0, 1, size=(21, latent_dim, 1, 1), ctx=device)\n",
    "        # Rescale output from [-1, 1] to [0, 1]\n",
    "        fake_x = net_G(Z).transpose(0, 2, 3, 1) / 2 + 0.5\n",
    "        imgs = np.concatenate(\n",
    "            [np.concatenate([fake_x[i * 7 + j] for j in range(7)], axis=1)\n",
    "             for i in range(len(fake_x)//7)], axis=0)\n",
    "        animator.axes[1].cla()\n",
    "        animator.axes[1].imshow(imgs.asnumpy())\n",
    "        # Show the losses\n",
    "        loss_D, loss_G = metric[0] / metric[2], metric[1] / metric[2]\n",
    "        animator.add(epoch, (loss_D, loss_G))\n",
    "    print(f'loss_D {loss_D:.3f}, loss_G {loss_G:.3f}, '\n",
    "          f'{metric[2] / timer.stop():.1f} examples/sec on {str(device)}')"
   ],
   "execution_count": 15,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=dcgan-md-16 fw=all -->\n",
    "\n",
    "We train the model with a small number of epochs just for demonstration.\n",
    "For better performance,\n",
    "the variable `num_epochs` can be set to a larger number.\n",
    "GAN losses should not be read like supervised validation loss: a large\n",
    "generator loss can coexist with useful samples when the discriminator is\n",
    "confident. Inspect the generated image grid in the lower panel as the primary\n",
    "teaching signal, and use longer runs when comparing architectures."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "dcgan-training-2"
   },
   "source": [
    "latent_dim, lr, num_epochs = 100, 0.0002, 40\n",
    "train(net_D, net_G, data_iter, num_epochs, lr, latent_dim)"
   ],
   "execution_count": 16,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "loss_D 0.384, loss_G 3.955, 1245.9 examples/sec on gpu(0)\n"
     ]
    },
    {
     "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=\"333.165625pt\" height=\"310.279886pt\" viewBox=\"0 0 333.165625 310.279886\" 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-19T15:56:11.196028</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 310.279886 \nL 333.165625 310.279886 \nL 333.165625 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 40.603125 130.198656 \nL 319.603125 130.198656 \nL 319.603125 9.676917 \nL 40.603125 9.676917 \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 d=\"M 69.21851 130.198656 \nL 69.21851 9.676917 \n\" clip-path=\"url(#pcafb6b1f62)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_2\">\n      <defs>\n       <path id=\"m22a31f3eae\" d=\"M 0 0 \nL 0 3.5 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#m22a31f3eae\" x=\"69.21851\" y=\"130.198656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_1\">\n      <!-- 5 -->\n      <g transform=\"translate(66.03726 144.797093) scale(0.1 -0.1)\">\n       <defs>\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-35\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_2\">\n     <g id=\"line2d_3\">\n      <path d=\"M 104.98774 130.198656 \nL 104.98774 9.676917 \n\" clip-path=\"url(#pcafb6b1f62)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_4\">\n      <g>\n       <use xlink:href=\"#m22a31f3eae\" x=\"104.98774\" y=\"130.198656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_2\">\n      <!-- 10 -->\n      <g transform=\"translate(98.62524 144.797093) 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        <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-31\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_3\">\n     <g id=\"line2d_5\">\n      <path d=\"M 140.756971 130.198656 \nL 140.756971 9.676917 \n\" clip-path=\"url(#pcafb6b1f62)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_6\">\n      <g>\n       <use xlink:href=\"#m22a31f3eae\" x=\"140.756971\" y=\"130.198656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_3\">\n      <!-- 15 -->\n      <g transform=\"translate(134.394471 144.797093) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-31\"/>\n       <use xlink:href=\"#DejaVuSans-35\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_4\">\n     <g id=\"line2d_7\">\n      <path d=\"M 176.526202 130.198656 \nL 176.526202 9.676917 \n\" clip-path=\"url(#pcafb6b1f62)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_8\">\n      <g>\n       <use xlink:href=\"#m22a31f3eae\" x=\"176.526202\" y=\"130.198656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_4\">\n      <!-- 20 -->\n      <g transform=\"translate(170.163702 144.797093) 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       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_5\">\n     <g id=\"line2d_9\">\n      <path d=\"M 212.295433 130.198656 \nL 212.295433 9.676917 \n\" clip-path=\"url(#pcafb6b1f62)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_10\">\n      <g>\n       <use xlink:href=\"#m22a31f3eae\" x=\"212.295433\" y=\"130.198656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_5\">\n      <!-- 25 -->\n      <g transform=\"translate(205.932933 144.797093) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-32\"/>\n       <use xlink:href=\"#DejaVuSans-35\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_6\">\n     <g id=\"line2d_11\">\n      <path d=\"M 248.064663 130.198656 \nL 248.064663 9.676917 \n\" clip-path=\"url(#pcafb6b1f62)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_12\">\n      <g>\n       <use xlink:href=\"#m22a31f3eae\" x=\"248.064663\" y=\"130.198656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_6\">\n      <!-- 30 -->\n      <g transform=\"translate(241.702163 144.797093) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-33\" d=\"M 2597 2516 \nQ 3050 2419 3304 2112 \nQ 3559 1806 3559 1356 \nQ 3559 666 3084 287 \nQ 2609 -91 1734 -91 \nQ 1441 -91 1130 -33 \nQ 819 25 488 141 \nL 488 750 \nQ 750 597 1062 519 \nQ 1375 441 1716 441 \nQ 2309 441 2620 675 \nQ 2931 909 2931 1356 \nQ 2931 1769 2642 2001 \nQ 2353 2234 1838 2234 \nL 1294 2234 \nL 1294 2753 \nL 1863 2753 \nQ 2328 2753 2575 2939 \nQ 2822 3125 2822 3475 \nQ 2822 3834 2567 4026 \nQ 2313 4219 1838 4219 \nQ 1578 4219 1281 4162 \nQ 984 4106 628 3988 \nL 628 4550 \nQ 988 4650 1302 4700 \nQ 1616 4750 1894 4750 \nQ 2613 4750 3031 4423 \nQ 3450 4097 3450 3541 \nQ 3450 3153 3228 2886 \nQ 3006 2619 2597 2516 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-33\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_7\">\n     <g id=\"line2d_13\">\n      <path d=\"M 283.833894 130.198656 \nL 283.833894 9.676917 \n\" clip-path=\"url(#pcafb6b1f62)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_14\">\n      <g>\n       <use xlink:href=\"#m22a31f3eae\" x=\"283.833894\" y=\"130.198656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_7\">\n      <!-- 35 -->\n      <g transform=\"translate(277.471394 144.797093) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-33\"/>\n       <use xlink:href=\"#DejaVuSans-35\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_8\">\n     <g id=\"line2d_15\">\n      <path d=\"M 319.603125 130.198656 \nL 319.603125 9.676917 \n\" clip-path=\"url(#pcafb6b1f62)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_16\">\n      <g>\n       <use xlink:href=\"#m22a31f3eae\" x=\"319.603125\" y=\"130.198656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_8\">\n      <!-- 40 -->\n      <g transform=\"translate(313.240625 144.797093) 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       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"text_9\">\n     <!-- epoch -->\n     <g transform=\"translate(164.875 158.475218) 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_17\">\n      <path d=\"M 40.603125 124.950012 \nL 319.603125 124.950012 \n\" clip-path=\"url(#pcafb6b1f62)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_18\">\n      <defs>\n       <path id=\"mcd5dc5d0b8\" d=\"M 0 0 \nL -3.5 0 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#mcd5dc5d0b8\" x=\"40.603125\" y=\"124.950012\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_10\">\n      <!-- 0 -->\n      <g transform=\"translate(27.240625 128.749231) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_2\">\n     <g id=\"line2d_19\">\n      <path d=\"M 40.603125 102.159853 \nL 319.603125 102.159853 \n\" clip-path=\"url(#pcafb6b1f62)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_20\">\n      <g>\n       <use xlink:href=\"#mcd5dc5d0b8\" x=\"40.603125\" y=\"102.159853\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_11\">\n      <!-- 2 -->\n      <g transform=\"translate(27.240625 105.959072) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-32\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_3\">\n     <g id=\"line2d_21\">\n      <path d=\"M 40.603125 79.369695 \nL 319.603125 79.369695 \n\" clip-path=\"url(#pcafb6b1f62)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_22\">\n      <g>\n       <use xlink:href=\"#mcd5dc5d0b8\" x=\"40.603125\" y=\"79.369695\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_12\">\n      <!-- 4 -->\n      <g transform=\"translate(27.240625 83.168914) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-34\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_4\">\n     <g id=\"line2d_23\">\n      <path d=\"M 40.603125 56.579536 \nL 319.603125 56.579536 \n\" clip-path=\"url(#pcafb6b1f62)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_24\">\n      <g>\n       <use xlink:href=\"#mcd5dc5d0b8\" x=\"40.603125\" y=\"56.579536\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_13\">\n      <!-- 6 -->\n      <g transform=\"translate(27.240625 60.378755) 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=\"ytick_5\">\n     <g id=\"line2d_25\">\n      <path d=\"M 40.603125 33.789377 \nL 319.603125 33.789377 \n\" clip-path=\"url(#pcafb6b1f62)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_26\">\n      <g>\n       <use xlink:href=\"#mcd5dc5d0b8\" x=\"40.603125\" y=\"33.789377\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_14\">\n      <!-- 8 -->\n      <g transform=\"translate(27.240625 37.588596) 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=\"ytick_6\">\n     <g id=\"line2d_27\">\n      <path d=\"M 40.603125 10.999219 \nL 319.603125 10.999219 \n\" clip-path=\"url(#pcafb6b1f62)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_28\">\n      <g>\n       <use xlink:href=\"#mcd5dc5d0b8\" x=\"40.603125\" y=\"10.999219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_15\">\n      <!-- 10 -->\n      <g transform=\"translate(20.878125 14.798437) scale(0.1 -0.1)\">\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_16\">\n     <!-- loss -->\n     <g transform=\"translate(14.798438 79.595599) rotate(-90) scale(0.1 -0.1)\">\n      <defs>\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-6c\"/>\n      <use xlink:href=\"#DejaVuSans-6f\" transform=\"translate(27.783203 0)\"/>\n      <use xlink:href=\"#DejaVuSans-73\" transform=\"translate(88.964844 0)\"/>\n      <use xlink:href=\"#DejaVuSans-73\" transform=\"translate(141.064453 0)\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"line2d_29\">\n    <path d=\"M 40.603125 118.526836 \nL 47.756971 122.931869 \nL 54.910817 122.123688 \nL 62.064663 121.690329 \nL 69.21851 122.065638 \nL 76.372356 121.755712 \nL 83.526202 122.005638 \nL 90.680048 122.185689 \nL 97.833894 122.496121 \nL 104.98774 122.232459 \nL 112.141587 122.340443 \nL 119.295433 122.653113 \nL 126.449279 122.919555 \nL 133.603125 122.545209 \nL 140.756971 123.117538 \nL 147.910817 122.747316 \nL 155.064663 123.023211 \nL 162.21851 123.003623 \nL 169.372356 123.08634 \nL 176.526202 123.759574 \nL 183.680048 122.829724 \nL 190.833894 123.666629 \nL 197.98774 123.130631 \nL 205.141587 123.505381 \nL 212.295433 123.967935 \nL 219.449279 123.741199 \nL 226.603125 122.881512 \nL 233.756971 124.012719 \nL 240.910817 124.514518 \nL 248.064663 123.109257 \nL 255.21851 124.286272 \nL 262.372356 123.640153 \nL 269.526202 124.294118 \nL 276.680048 124.614275 \nL 283.833894 124.208718 \nL 290.98774 123.171039 \nL 298.141587 124.653243 \nL 305.295433 124.720395 \nL 312.449279 124.719601 \nL 319.603125 120.570373 \n\" clip-path=\"url(#pcafb6b1f62)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n   </g>\n   <g id=\"line2d_30\">\n    <path d=\"M 40.603125 15.155178 \nL 47.756971 67.348577 \nL 54.910817 83.64299 \nL 62.064663 83.378406 \nL 69.21851 81.44741 \nL 76.372356 83.112629 \nL 83.526202 84.158531 \nL 90.680048 82.693315 \nL 97.833894 85.756435 \nL 104.98774 85.45538 \nL 112.141587 84.400191 \nL 119.295433 82.028943 \nL 126.449279 84.703254 \nL 133.603125 84.465218 \nL 140.756971 86.872713 \nL 147.910817 84.878832 \nL 155.064663 84.904979 \nL 162.21851 83.785898 \nL 169.372356 83.505873 \nL 176.526202 85.305288 \nL 183.680048 83.919006 \nL 190.833894 85.295607 \nL 197.98774 82.670123 \nL 205.141587 85.288145 \nL 212.295433 82.407269 \nL 219.449279 79.149629 \nL 226.603125 84.219858 \nL 233.756971 82.301537 \nL 240.910817 79.133198 \nL 248.064663 77.723469 \nL 255.21851 82.481177 \nL 262.372356 77.230079 \nL 269.526202 80.909084 \nL 276.680048 75.727375 \nL 283.833894 72.668182 \nL 290.98774 81.164104 \nL 298.141587 74.274311 \nL 305.295433 70.787273 \nL 312.449279 69.084241 \nL 319.603125 79.880864 \n\" clip-path=\"url(#pcafb6b1f62)\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #bf00bf; stroke-width: 1.5\"/>\n   </g>\n   <g id=\"patch_3\">\n    <path d=\"M 40.603125 130.198656 \nL 40.603125 9.676917 \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 319.603125 130.198656 \nL 319.603125 9.676917 \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 40.603125 130.198656 \nL 319.603125 130.198656 \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 40.603125 9.676917 \nL 319.603125 9.676917 \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 214.745312 47.033167 \nL 312.603125 47.033167 \nQ 314.603125 47.033167 314.603125 45.033167 \nL 314.603125 16.676917 \nQ 314.603125 14.676917 312.603125 14.676917 \nL 214.745312 14.676917 \nQ 212.745312 14.676917 212.745312 16.676917 \nL 212.745312 45.033167 \nQ 212.745312 47.033167 214.745312 47.033167 \nz\n\" style=\"fill: #ffffff; opacity: 0.8; stroke: #cccccc; stroke-linejoin: miter\"/>\n    </g>\n    <g id=\"line2d_31\">\n     <path d=\"M 216.745312 22.775354 \nL 226.745312 22.775354 \nL 236.745312 22.775354 \n\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n    </g>\n    <g id=\"text_17\">\n     <!-- discriminator -->\n     <g transform=\"translate(244.745312 26.275354) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"DejaVuSans-64\" d=\"M 2906 2969 \nL 2906 4863 \nL 3481 4863 \nL 3481 0 \nL 2906 0 \nL 2906 525 \nQ 2725 213 2448 61 \nQ 2172 -91 1784 -91 \nQ 1150 -91 751 415 \nQ 353 922 353 1747 \nQ 353 2572 751 3078 \nQ 1150 3584 1784 3584 \nQ 2172 3584 2448 3432 \nQ 2725 3281 2906 2969 \nz\nM 947 1747 \nQ 947 1113 1208 752 \nQ 1469 391 1925 391 \nQ 2381 391 2643 752 \nQ 2906 1113 2906 1747 \nQ 2906 2381 2643 2742 \nQ 2381 3103 1925 3103 \nQ 1469 3103 1208 2742 \nQ 947 2381 947 1747 \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-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-6d\" d=\"M 3328 2828 \nQ 3544 3216 3844 3400 \nQ 4144 3584 4550 3584 \nQ 5097 3584 5394 3201 \nQ 5691 2819 5691 2113 \nL 5691 0 \nL 5113 0 \nL 5113 2094 \nQ 5113 2597 4934 2840 \nQ 4756 3084 4391 3084 \nQ 3944 3084 3684 2787 \nQ 3425 2491 3425 1978 \nL 3425 0 \nL 2847 0 \nL 2847 2094 \nQ 2847 2600 2669 2842 \nQ 2491 3084 2119 3084 \nQ 1678 3084 1418 2786 \nQ 1159 2488 1159 1978 \nL 1159 0 \nL 581 0 \nL 581 3500 \nL 1159 3500 \nL 1159 2956 \nQ 1356 3278 1631 3431 \nQ 1906 3584 2284 3584 \nQ 2666 3584 2933 3390 \nQ 3200 3197 3328 2828 \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-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-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      </defs>\n      <use xlink:href=\"#DejaVuSans-64\"/>\n      <use xlink:href=\"#DejaVuSans-69\" transform=\"translate(63.476562 0)\"/>\n      <use xlink:href=\"#DejaVuSans-73\" transform=\"translate(91.259766 0)\"/>\n      <use xlink:href=\"#DejaVuSans-63\" transform=\"translate(143.359375 0)\"/>\n      <use xlink:href=\"#DejaVuSans-72\" transform=\"translate(198.339844 0)\"/>\n      <use xlink:href=\"#DejaVuSans-69\" transform=\"translate(239.453125 0)\"/>\n      <use xlink:href=\"#DejaVuSans-6d\" transform=\"translate(267.236328 0)\"/>\n      <use xlink:href=\"#DejaVuSans-69\" transform=\"translate(364.648438 0)\"/>\n      <use xlink:href=\"#DejaVuSans-6e\" transform=\"translate(392.431641 0)\"/>\n      <use xlink:href=\"#DejaVuSans-61\" transform=\"translate(455.810547 0)\"/>\n      <use xlink:href=\"#DejaVuSans-74\" transform=\"translate(517.089844 0)\"/>\n      <use xlink:href=\"#DejaVuSans-6f\" transform=\"translate(556.298828 0)\"/>\n      <use xlink:href=\"#DejaVuSans-72\" transform=\"translate(617.480469 0)\"/>\n     </g>\n    </g>\n    <g id=\"line2d_32\">\n     <path d=\"M 216.745312 37.453479 \nL 226.745312 37.453479 \nL 236.745312 37.453479 \n\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #bf00bf; stroke-width: 1.5\"/>\n    </g>\n    <g id=\"text_18\">\n     <!-- generator -->\n     <g transform=\"translate(244.745312 40.953479) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"DejaVuSans-67\" d=\"M 2906 1791 \nQ 2906 2416 2648 2759 \nQ 2391 3103 1925 3103 \nQ 1463 3103 1205 2759 \nQ 947 2416 947 1791 \nQ 947 1169 1205 825 \nQ 1463 481 1925 481 \nQ 2391 481 2648 825 \nQ 2906 1169 2906 1791 \nz\nM 3481 434 \nQ 3481 -459 3084 -895 \nQ 2688 -1331 1869 -1331 \nQ 1566 -1331 1297 -1286 \nQ 1028 -1241 775 -1147 \nL 775 -588 \nQ 1028 -725 1275 -790 \nQ 1522 -856 1778 -856 \nQ 2344 -856 2625 -561 \nQ 2906 -266 2906 331 \nL 2906 616 \nQ 2728 306 2450 153 \nQ 2172 0 1784 0 \nQ 1141 0 747 490 \nQ 353 981 353 1791 \nQ 353 2603 747 3093 \nQ 1141 3584 1784 3584 \nQ 2172 3584 2450 3431 \nQ 2728 3278 2906 2969 \nL 2906 3500 \nL 3481 3500 \nL 3481 434 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#DejaVuSans-67\"/>\n      <use xlink:href=\"#DejaVuSans-65\" transform=\"translate(63.476562 0)\"/>\n      <use xlink:href=\"#DejaVuSans-6e\" transform=\"translate(125 0)\"/>\n      <use xlink:href=\"#DejaVuSans-65\" transform=\"translate(188.378906 0)\"/>\n      <use xlink:href=\"#DejaVuSans-72\" transform=\"translate(249.902344 0)\"/>\n      <use xlink:href=\"#DejaVuSans-61\" transform=\"translate(291.015625 0)\"/>\n      <use xlink:href=\"#DejaVuSans-74\" transform=\"translate(352.294922 0)\"/>\n      <use xlink:href=\"#DejaVuSans-6f\" transform=\"translate(391.503906 0)\"/>\n      <use xlink:href=\"#DejaVuSans-72\" transform=\"translate(452.685547 0)\"/>\n     </g>\n    </g>\n   </g>\n  </g>\n  <g id=\"axes_2\">\n   <g id=\"patch_8\">\n    <path d=\"M 40.603125 286.401761 \nL 319.603125 286.401761 \nL 319.603125 166.830333 \nL 40.603125 166.830333 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#p330299ea10)\">\n    <image xlink:href=\"data:image/png;base64,\[encoded data, 176869 characters]\" id=\"image7defb4f5df\" transform=\"scale(1 -1) translate(0 -120.24)\" x=\"40.603125\" y=\"-166.161761\" width=\"279.36\" height=\"120.24\"/>\n   </g>\n   <g id=\"matplotlib.axis_3\">\n    <g id=\"xtick_9\">\n     <g id=\"line2d_33\">\n      <g>\n       <use xlink:href=\"#m22a31f3eae\" x=\"40.914509\" y=\"286.401761\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_19\">\n      <!-- 0 -->\n      <g transform=\"translate(37.733259 301.000199) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_10\">\n     <g id=\"line2d_34\">\n      <g>\n       <use xlink:href=\"#m22a31f3eae\" x=\"72.052902\" y=\"286.401761\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_20\">\n      <!-- 50 -->\n      <g transform=\"translate(65.690402 301.000199) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-35\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_11\">\n     <g id=\"line2d_35\">\n      <g>\n       <use xlink:href=\"#m22a31f3eae\" x=\"103.191295\" y=\"286.401761\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_21\">\n      <!-- 100 -->\n      <g transform=\"translate(93.647545 301.000199) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-31\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(127.246094 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_12\">\n     <g id=\"line2d_36\">\n      <g>\n       <use xlink:href=\"#m22a31f3eae\" x=\"134.329688\" y=\"286.401761\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_22\">\n      <!-- 150 -->\n      <g transform=\"translate(124.785938 301.000199) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-31\"/>\n       <use xlink:href=\"#DejaVuSans-35\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(127.246094 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_13\">\n     <g id=\"line2d_37\">\n      <g>\n       <use xlink:href=\"#m22a31f3eae\" x=\"165.46808\" y=\"286.401761\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_23\">\n      <!-- 200 -->\n      <g transform=\"translate(155.92433 301.000199) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-32\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(127.246094 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_14\">\n     <g id=\"line2d_38\">\n      <g>\n       <use xlink:href=\"#m22a31f3eae\" x=\"196.606473\" y=\"286.401761\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_24\">\n      <!-- 250 -->\n      <g transform=\"translate(187.062723 301.000199) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-32\"/>\n       <use xlink:href=\"#DejaVuSans-35\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(127.246094 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_15\">\n     <g id=\"line2d_39\">\n      <g>\n       <use xlink:href=\"#m22a31f3eae\" x=\"227.744866\" y=\"286.401761\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_25\">\n      <!-- 300 -->\n      <g transform=\"translate(218.201116 301.000199) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-33\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(127.246094 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_16\">\n     <g id=\"line2d_40\">\n      <g>\n       <use xlink:href=\"#m22a31f3eae\" x=\"258.883259\" y=\"286.401761\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_26\">\n      <!-- 350 -->\n      <g transform=\"translate(249.339509 301.000199) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-33\"/>\n       <use xlink:href=\"#DejaVuSans-35\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(127.246094 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_17\">\n     <g id=\"line2d_41\">\n      <g>\n       <use xlink:href=\"#m22a31f3eae\" x=\"290.021652\" y=\"286.401761\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_27\">\n      <!-- 400 -->\n      <g transform=\"translate(280.477902 301.000199) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-34\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(127.246094 0)\"/>\n      </g>\n     </g>\n    </g>\n   </g>\n   <g id=\"matplotlib.axis_4\">\n    <g id=\"ytick_7\">\n     <g id=\"line2d_42\">\n      <g>\n       <use xlink:href=\"#mcd5dc5d0b8\" x=\"40.603125\" y=\"167.141717\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_28\">\n      <!-- 0 -->\n      <g transform=\"translate(27.240625 170.940936) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_8\">\n     <g id=\"line2d_43\">\n      <g>\n       <use xlink:href=\"#mcd5dc5d0b8\" x=\"40.603125\" y=\"198.28011\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_29\">\n      <!-- 50 -->\n      <g transform=\"translate(20.878125 202.079328) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-35\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_9\">\n     <g id=\"line2d_44\">\n      <g>\n       <use xlink:href=\"#mcd5dc5d0b8\" x=\"40.603125\" y=\"229.418503\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_30\">\n      <!-- 100 -->\n      <g transform=\"translate(14.515625 233.217721) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-31\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(127.246094 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_10\">\n     <g id=\"line2d_45\">\n      <g>\n       <use xlink:href=\"#mcd5dc5d0b8\" x=\"40.603125\" y=\"260.556895\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_31\">\n      <!-- 150 -->\n      <g transform=\"translate(14.515625 264.356114) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-31\"/>\n       <use xlink:href=\"#DejaVuSans-35\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(127.246094 0)\"/>\n      </g>\n     </g>\n    </g>\n   </g>\n   <g id=\"patch_9\">\n    <path d=\"M 40.603125 286.401761 \nL 40.603125 166.830333 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_10\">\n    <path d=\"M 319.603125 286.401761 \nL 319.603125 166.830333 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_11\">\n    <path d=\"M 40.603125 286.401761 \nL 319.603125 286.401761 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_12\">\n    <path d=\"M 40.603125 166.830333 \nL 319.603125 166.830333 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n  </g>\n </g>\n <defs>\n  <clipPath id=\"pcafb6b1f62\">\n   <rect x=\"40.603125\" y=\"9.676917\" width=\"279\" height=\"120.521739\"/>\n  </clipPath>\n  <clipPath id=\"p330299ea10\">\n   <rect x=\"40.603125\" y=\"166.830333\" width=\"279\" height=\"119.571429\"/>\n  </clipPath>\n </defs>\n</svg>\n"
     },
     "metadata": {}
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=dcgan-md-17 fw=all -->\n",
    "\n",
    "## Summary\n",
    "\n",
    "* DCGAN architecture has four convolutional layers for the Discriminator and four \"fractionally-strided\" convolutional layers for the Generator.\n",
    "* The Discriminator is a 4-layer strided convolutions with batch normalization (except its input layer) and leaky ReLU activations.\n",
    "* Leaky ReLU is a nonlinear function that give a non-zero output for a negative input. It aims to fix the “dying ReLU” problem and helps the gradients flow easier through the architecture.\n",
    "\n",
    "\n",
    "## Exercises\n",
    "\n",
    "1. What will happen if we use standard ReLU activation rather than leaky ReLU?\n",
    "1. Apply DCGAN on Fashion-MNIST and see which category works well and which does not."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=dcgan-md-18 fw=mxnet -->\n",
    "\n",
    "[Discussions](https://d2l.discourse.group/t/409)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "name": "d2l-mxnet",
   "display_name": "d2l (MXNet)",
   "language": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
