{
 "cells": [
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "---\n",
    "execute:\n",
    "  enabled: false\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=fcn-md-1 fw=all -->\n",
    "\n",
    "# Fully Convolutional Networks\n",
    "\n",
    "As discussed in that section,\n",
    "semantic segmentation\n",
    "classifies images in pixel level.\n",
    "A fully convolutional network (FCN)\n",
    "uses a convolutional neural network to\n",
    "transform image pixels to pixel classes [@Long.Shelhamer.Darrell.2015].\n",
    "Unlike the CNNs that we encountered earlier\n",
    "for image classification \n",
    "or object detection,\n",
    "a fully convolutional network\n",
    "transforms \n",
    "the height and width of intermediate feature maps\n",
    "back to those of the input image:\n",
    "this is achieved by\n",
    "the transposed convolutional layer\n",
    "introduced in that section.\n",
    "As a result,\n",
    "the classification output\n",
    "and the input image \n",
    "have a one-to-one correspondence \n",
    "in pixel level:\n",
    "the channel dimension at any output pixel \n",
    "holds the classification results\n",
    "for the input pixel at the same spatial position."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "fcn-fully-convolutional-networks"
   },
   "source": [
    "%matplotlib inline\n",
    "from d2l import mxnet as d2l\n",
    "from mxnet import gluon, image, init, np, npx\n",
    "from mxnet.gluon import nn\n",
    "\n",
    "npx.set_np()"
   ],
   "execution_count": 1,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=fcn-md-2 fw=all -->\n",
    "\n",
    "## The Model\n",
    "\n",
    "Here we describe the basic design of the fully convolutional network model. \n",
    "As shown in the figure,\n",
    "this model first uses a CNN to extract image features,\n",
    "then transforms the number of channels into\n",
    "the number of classes\n",
    "via a $1\\times 1$ convolutional layer,\n",
    "and finally transforms the height and width of\n",
    "the feature maps\n",
    "to those\n",
    "of the input image via\n",
    "the transposed convolution introduced in that section. \n",
    "As a result,\n",
    "the model output has the same height and width as the input image,\n",
    "where the output channel contains the predicted classes\n",
    "for the input pixel at the same spatial position.\n",
    "\n",
    "\n",
    "![Fully convolutional network.](../img/fcn.svg)\n",
    "\n",
    "Below, we use a ResNet model pretrained on the ImageNet dataset to extract image features\n",
    "and denote the model instance as `pretrained_net`.\n",
    "The last few layers of this model\n",
    "include a global average pooling layer\n",
    "and a fully connected layer:\n",
    "they are not needed\n",
    "in the fully convolutional network."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "fcn-the-model-1"
   },
   "source": [
    "pretrained_net = gluon.model_zoo.vision.resnet18_v2(pretrained=True)\n",
    "pretrained_net.features[-3:], pretrained_net.output"
   ],
   "execution_count": 2,
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "(HybridSequential(\n   (0): Activation(relu)\n   (1): GlobalAvgPool2D(size=(1, 1), stride=(1, 1), padding=(0, 0), ceil_mode=True, global_pool=True, pool_type=avg, layout=NCHW)\n   (2): Flatten\n ),\n Dense(512 -> 1000, linear))"
     },
     "metadata": {},
     "execution_count": 2
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=fcn-md-3 fw=all -->\n",
    "\n",
    "Next, we create the fully convolutional network instance `net`.\n",
    "It copies all the pretrained convolutional layers in the ResNet\n",
    "except for the final global average pooling layer\n",
    "and the fully connected layer that are closest\n",
    "to the output."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "fcn-the-model-2"
   },
   "source": [
    "net = nn.HybridSequential()\n",
    "for layer in pretrained_net.features[:-2]:\n",
    "    net.add(layer)"
   ],
   "execution_count": 3,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=fcn-md-4 fw=all -->\n",
    "\n",
    "Given an input with height and width of 320 and 480 respectively,\n",
    "the forward propagation of `net`\n",
    "reduces the input height and width to 1/32 of the original, namely 10 and 15."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "fcn-the-model-3"
   },
   "source": [
    "X = np.random.uniform(size=(1, 3, 320, 480))\n",
    "net(X).shape"
   ],
   "execution_count": 4,
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "(1, 512, 10, 15)"
     },
     "metadata": {},
     "execution_count": 4
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=fcn-md-5 fw=all -->\n",
    "\n",
    "Next, we use a $1\\times 1$ convolutional layer to transform the number of output channels into the number of classes (21) of the Pascal VOC2012 dataset.\n",
    "Finally, we need to increase the height and width of the feature maps by 32 times to change them back to the height and width of the input image. \n",
    "Recall how to calculate \n",
    "the output shape of a convolutional layer in that section. \n",
    "Since $(320-64+16\\times2+32)/32=10$ and $(480-64+16\\times2+32)/32=15$, we construct a transposed convolutional layer with stride of $32$, \n",
    "setting\n",
    "the height and width of the kernel\n",
    "to $64$, the padding to $16$.\n",
    "In general,\n",
    "we can see that\n",
    "for stride $s$,\n",
    "padding $s/2$ (assuming $s/2$ is an integer),\n",
    "and the height and width of the kernel $2s$, \n",
    "the transposed convolution will increase\n",
    "the height and width of the input by $s$ times."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "fcn-the-model-4"
   },
   "source": [
    "num_classes = 21\n",
    "net.add(nn.Conv2D(num_classes, kernel_size=1),\n",
    "        nn.Conv2DTranspose(\n",
    "            num_classes, kernel_size=64, padding=16, strides=32))"
   ],
   "execution_count": 5,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=fcn-md-6 fw=all -->\n",
    "\n",
    "## Initializing Transposed Convolutional Layers\n",
    "\n",
    "\n",
    "We already know that\n",
    "transposed convolutional layers can increase\n",
    "the height and width of\n",
    "feature maps.\n",
    "In image processing, we may need to scale up\n",
    "an image, i.e., *upsampling*.\n",
    "*Bilinear interpolation*\n",
    "is one of the commonly used upsampling techniques.\n",
    "It is also often used for initializing transposed convolutional layers.\n",
    "\n",
    "To explain bilinear interpolation,\n",
    "say that \n",
    "given an input image\n",
    "we want to \n",
    "calculate each pixel \n",
    "of the upsampled output image.\n",
    "In order to calculate the pixel of the output image\n",
    "at coordinate $(x, y)$, \n",
    "first map $(x, y)$ to coordinate $(x', y')$ on the input image, for example, according to the ratio of the input size to the output size. \n",
    "Note that the mapped $x'$ and $y'$ are real numbers. \n",
    "Then, find the four pixels closest to coordinate\n",
    "$(x', y')$ on the input image. \n",
    "Finally, the pixel of the output image at coordinate $(x, y)$ is calculated based on these four closest pixels\n",
    "on the input image and their relative distance from $(x', y')$. \n",
    "\n",
    "Upsampling of bilinear interpolation\n",
    "can be implemented by the transposed convolutional layer \n",
    "with the kernel constructed by the following `bilinear_kernel` function. \n",
    "Due to space limitations, we only provide the implementation of the `bilinear_kernel` function below\n",
    "without discussions on its algorithm design."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "fcn-initializing-transposed-convolutional-layers-1"
   },
   "source": [
    "def bilinear_kernel(in_channels, out_channels, kernel_size):\n",
    "    factor = (kernel_size + 1) // 2\n",
    "    if kernel_size % 2 == 1:\n",
    "        center = factor - 1\n",
    "    else:\n",
    "        center = factor - 0.5\n",
    "    og = (np.arange(kernel_size).reshape(-1, 1),\n",
    "          np.arange(kernel_size).reshape(1, -1))\n",
    "    filt = (1 - np.abs(og[0] - center) / factor) * \\\n",
    "           (1 - np.abs(og[1] - center) / factor)\n",
    "    weight = np.zeros((in_channels, out_channels, kernel_size, kernel_size))\n",
    "    weight[range(in_channels), range(out_channels), :, :] = filt\n",
    "    return np.array(weight)"
   ],
   "execution_count": 6,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=fcn-md-7 fw=all -->\n",
    "\n",
    "Let's experiment with upsampling of bilinear interpolation \n",
    "that is implemented by a transposed convolutional layer. \n",
    "We construct a transposed convolutional layer that \n",
    "doubles the height and weight,\n",
    "and initialize its kernel with the `bilinear_kernel` function."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "fcn-initializing-transposed-convolutional-layers-2"
   },
   "source": [
    "conv_trans = nn.Conv2DTranspose(3, kernel_size=4, padding=1, strides=2)\n",
    "conv_trans.initialize(init.Constant(bilinear_kernel(3, 3, 4)))"
   ],
   "execution_count": 7,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=fcn-md-8 fw=all -->\n",
    "\n",
    "Read the image `X` and assign the upsampling output to `Y`. In order to print the image, we need to adjust the position of the channel dimension."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "fcn-initializing-transposed-convolutional-layers-3"
   },
   "source": [
    "img = image.imread('../img/catdog.jpg')\n",
    "X = np.expand_dims(img.astype('float32').transpose(2, 0, 1), axis=0) / 255\n",
    "Y = conv_trans(X)\n",
    "out_img = Y[0].transpose(1, 2, 0)"
   ],
   "execution_count": 8,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=fcn-md-9 fw=all -->\n",
    "\n",
    "As we can see, the transposed convolutional layer increases both the height and width of the image by a factor of two.\n",
    "Except for the different scales in coordinates,\n",
    "the image scaled up by bilinear interpolation and the original image printed in that section look the same."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "fcn-initializing-transposed-convolutional-layers-4"
   },
   "source": [
    "d2l.set_figsize()\n",
    "print('input image shape:', img.shape)\n",
    "d2l.plt.imshow(img.asnumpy());\n",
    "print('output image shape:', out_img.shape)\n",
    "d2l.plt.imshow(out_img.asnumpy());"
   ],
   "execution_count": 9,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "input image shape: (561, 728, 3)\noutput image shape: (1122, 1456, 3)\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=\"226.708824pt\" height=\"173.415579pt\" viewBox=\"0 0 226.708824 173.415579\" 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:19:28.424423</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 173.415579 \nL 226.708824 173.415579 \nL 226.708824 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 39.65 149.537454 \nL 219.508824 149.537454 \nL 219.508824 10.937454 \nL 39.65 10.937454 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#p8bd1898ff6)\">\n    <image xlink:href=\"data:image/png;base64,\[encoded data, 75221 characters]\" id=\"image05152106c8\" transform=\"scale(1 -1) translate(0 -138.96)\" x=\"40\" y=\"-10.455579\" width=\"180\" height=\"138.96\"/>\n   </g>\n   <g id=\"matplotlib.axis_1\">\n    <g id=\"xtick_1\">\n     <g id=\"line2d_1\">\n      <defs>\n       <path id=\"m7e45098874\" d=\"M 0 0 \nL 0 3.5 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#m7e45098874\" x=\"39.711765\" y=\"149.537454\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_1\">\n      <!-- 0 -->\n      <g transform=\"translate(36.530515 164.135892) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \nQ 1547 4250 1301 3770 \nQ 1056 3291 1056 2328 \nQ 1056 1369 1301 889 \nQ 1547 409 2034 409 \nQ 2525 409 2770 889 \nQ 3016 1369 3016 2328 \nQ 3016 3291 2770 3770 \nQ 2525 4250 2034 4250 \nz\nM 2034 4750 \nQ 2819 4750 3233 4129 \nQ 3647 3509 3647 2328 \nQ 3647 1150 3233 529 \nQ 2819 -91 2034 -91 \nQ 1250 -91 836 529 \nQ 422 1150 422 2328 \nQ 422 3509 836 4129 \nQ 1250 4750 2034 4750 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-30\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_2\">\n     <g id=\"line2d_2\">\n      <g>\n       <use xlink:href=\"#m7e45098874\" x=\"101.476471\" y=\"149.537454\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_2\">\n      <!-- 500 -->\n      <g transform=\"translate(91.932721 164.135892) 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       <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_3\">\n     <g id=\"line2d_3\">\n      <g>\n       <use xlink:href=\"#m7e45098874\" x=\"163.241176\" y=\"149.537454\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_3\">\n      <!-- 1000 -->\n      <g transform=\"translate(150.516176 164.135892) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-31\" d=\"M 794 531 \nL 1825 531 \nL 1825 4091 \nL 703 3866 \nL 703 4441 \nL 1819 4666 \nL 2450 4666 \nL 2450 531 \nL 3481 531 \nL 3481 0 \nL 794 0 \nL 794 531 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-31\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(127.246094 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(190.869141 0)\"/>\n      </g>\n     </g>\n    </g>\n   </g>\n   <g id=\"matplotlib.axis_2\">\n    <g id=\"ytick_1\">\n     <g id=\"line2d_4\">\n      <defs>\n       <path id=\"m5ba89cfc52\" d=\"M 0 0 \nL -3.5 0 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#m5ba89cfc52\" x=\"39.65\" y=\"10.999219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_4\">\n      <!-- 0 -->\n      <g transform=\"translate(26.2875 14.798438) 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_5\">\n      <g>\n       <use xlink:href=\"#m5ba89cfc52\" x=\"39.65\" y=\"35.705101\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_5\">\n      <!-- 200 -->\n      <g transform=\"translate(13.5625 39.50432) 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       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(127.246094 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_3\">\n     <g id=\"line2d_6\">\n      <g>\n       <use xlink:href=\"#m5ba89cfc52\" x=\"39.65\" y=\"60.410983\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_6\">\n      <!-- 400 -->\n      <g transform=\"translate(13.5625 64.210202) 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       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(127.246094 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_4\">\n     <g id=\"line2d_7\">\n      <g>\n       <use xlink:href=\"#m5ba89cfc52\" x=\"39.65\" y=\"85.116866\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_7\">\n      <!-- 600 -->\n      <g transform=\"translate(13.5625 88.916085) 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       <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_5\">\n     <g id=\"line2d_8\">\n      <g>\n       <use xlink:href=\"#m5ba89cfc52\" x=\"39.65\" y=\"109.822748\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_8\">\n      <!-- 800 -->\n      <g transform=\"translate(13.5625 113.621967) 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       <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_6\">\n     <g id=\"line2d_9\">\n      <g>\n       <use xlink:href=\"#m5ba89cfc52\" x=\"39.65\" y=\"134.528631\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_9\">\n      <!-- 1000 -->\n      <g transform=\"translate(7.2 138.327849) 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       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(190.869141 0)\"/>\n      </g>\n     </g>\n    </g>\n   </g>\n   <g id=\"patch_3\">\n    <path d=\"M 39.65 149.537454 \nL 39.65 10.937454 \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 219.508824 149.537454 \nL 219.508824 10.937454 \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 39.65 149.537454 \nL 219.508824 149.537454 \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 39.65 10.937454 \nL 219.508824 10.937454 \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=\"p8bd1898ff6\">\n   <rect x=\"39.65\" y=\"10.937454\" width=\"179.858824\" height=\"138.6\"/>\n  </clipPath>\n </defs>\n</svg>\n"
     },
     "metadata": {}
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=fcn-md-10 fw=all -->\n",
    "\n",
    "In a fully convolutional network, we initialize the transposed convolutional layer with upsampling of bilinear interpolation. For the $1\\times 1$ convolutional layer, we use Xavier initialization."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "fcn-initializing-transposed-convolutional-layers-5"
   },
   "source": [
    "W = bilinear_kernel(num_classes, num_classes, 64)\n",
    "net[-1].initialize(init.Constant(W))\n",
    "net[-2].initialize(init=init.Xavier())"
   ],
   "execution_count": 10,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=fcn-md-11 fw=all -->\n",
    "\n",
    "## Reading the Dataset\n",
    "\n",
    "We read\n",
    "the semantic segmentation dataset\n",
    "as introduced in that section. \n",
    "The output image shape of random cropping is\n",
    "specified as $320\\times 480$: both the height and width are divisible by $32$."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "fcn-reading-the-dataset"
   },
   "source": [
    "batch_size, crop_size = 32, (320, 480)\n",
    "train_iter, test_iter = d2l.load_data_voc(batch_size, crop_size)"
   ],
   "execution_count": 11,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "read 1114 examples\n"
     ]
    },
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "read 1078 examples\n"
     ]
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=fcn-md-12 fw=all -->\n",
    "\n",
    "## Training\n",
    "\n",
    "\n",
    "Now we can train our constructed\n",
    "fully convolutional network. \n",
    "The loss function and accuracy calculation here\n",
    "are not essentially different from those in image classification of earlier chapters. \n",
    "Because we use the output channel of the\n",
    "transposed convolutional layer to\n",
    "predict the class for each pixel,\n",
    "the channel dimension is specified in the loss calculation.\n",
    "In addition, the accuracy is calculated\n",
    "based on correctness\n",
    "of the predicted class for all the pixels."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "fcn-training"
   },
   "source": [
    "num_epochs, lr, wd, devices = 5, 0.001, 1e-3, d2l.try_all_gpus()\n",
    "loss = gluon.loss.SoftmaxCrossEntropyLoss(axis=1)\n",
    "net.reset_ctx(devices)\n",
    "trainer = gluon.Trainer(net.collect_params(), 'sgd',\n",
    "                        {'learning_rate': lr, 'wd': wd})\n",
    "d2l.train_ch13(net, train_iter, test_iter, loss, trainer, num_epochs, devices)"
   ],
   "execution_count": 12,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "loss 0.370, train acc 0.881, test acc 0.846\n85.1 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=\"235.784375pt\" height=\"187.155469pt\" viewBox=\"0 0 235.784375 187.155469\" 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:21:19.535416</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 187.155469 \nL 235.784375 187.155469 \nL 235.784375 0 \nL 0 0 \nz\n\" style=\"fill: #ffffff\"/>\n  </g>\n  <g id=\"axes_1\">\n   <g id=\"patch_2\">\n    <path d=\"M 30.103125 149.599219 \nL 225.403125 149.599219 \nL 225.403125 10.999219 \nL 30.103125 10.999219 \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 30.103125 149.599219 \nL 30.103125 10.999219 \n\" clip-path=\"url(#p392ca249e8)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_2\">\n      <defs>\n       <path id=\"m43d16aee60\" d=\"M 0 0 \nL 0 3.5 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#m43d16aee60\" x=\"30.103125\" y=\"149.599219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_1\">\n      <!-- 1 -->\n      <g transform=\"translate(26.921875 164.197656) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-31\" d=\"M 794 531 \nL 1825 531 \nL 1825 4091 \nL 703 3866 \nL 703 4441 \nL 1819 4666 \nL 2450 4666 \nL 2450 531 \nL 3481 531 \nL 3481 0 \nL 794 0 \nL 794 531 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-31\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_2\">\n     <g id=\"line2d_3\">\n      <path d=\"M 78.928125 149.599219 \nL 78.928125 10.999219 \n\" clip-path=\"url(#p392ca249e8)\" 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=\"#m43d16aee60\" x=\"78.928125\" y=\"149.599219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_2\">\n      <!-- 2 -->\n      <g transform=\"translate(75.746875 164.197656) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-32\" d=\"M 1228 531 \nL 3431 531 \nL 3431 0 \nL 469 0 \nL 469 531 \nQ 828 903 1448 1529 \nQ 2069 2156 2228 2338 \nQ 2531 2678 2651 2914 \nQ 2772 3150 2772 3378 \nQ 2772 3750 2511 3984 \nQ 2250 4219 1831 4219 \nQ 1534 4219 1204 4116 \nQ 875 4013 500 3803 \nL 500 4441 \nQ 881 4594 1212 4672 \nQ 1544 4750 1819 4750 \nQ 2544 4750 2975 4387 \nQ 3406 4025 3406 3419 \nQ 3406 3131 3298 2873 \nQ 3191 2616 2906 2266 \nQ 2828 2175 2409 1742 \nQ 1991 1309 1228 531 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-32\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_3\">\n     <g id=\"line2d_5\">\n      <path d=\"M 127.753125 149.599219 \nL 127.753125 10.999219 \n\" clip-path=\"url(#p392ca249e8)\" 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=\"#m43d16aee60\" x=\"127.753125\" y=\"149.599219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_3\">\n      <!-- 3 -->\n      <g transform=\"translate(124.571875 164.197656) 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      </g>\n     </g>\n    </g>\n    <g id=\"xtick_4\">\n     <g id=\"line2d_7\">\n      <path d=\"M 176.578125 149.599219 \nL 176.578125 10.999219 \n\" clip-path=\"url(#p392ca249e8)\" 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=\"#m43d16aee60\" x=\"176.578125\" y=\"149.599219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_4\">\n      <!-- 4 -->\n      <g transform=\"translate(173.396875 164.197656) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \nL 825 1625 \nL 2419 1625 \nL 2419 4116 \nz\nM 2253 4666 \nL 3047 4666 \nL 3047 1625 \nL 3713 1625 \nL 3713 1100 \nL 3047 1100 \nL 3047 0 \nL 2419 0 \nL 2419 1100 \nL 313 1100 \nL 313 1709 \nL 2253 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-34\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_5\">\n     <g id=\"line2d_9\">\n      <path d=\"M 225.403125 149.599219 \nL 225.403125 10.999219 \n\" clip-path=\"url(#p392ca249e8)\" 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=\"#m43d16aee60\" x=\"225.403125\" y=\"149.599219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_5\">\n      <!-- 5 -->\n      <g transform=\"translate(222.221875 164.197656) 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=\"text_6\">\n     <!-- epoch -->\n     <g transform=\"translate(112.525 177.875781) 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_11\">\n      <path d=\"M 30.103125 149.599219 \nL 225.403125 149.599219 \n\" clip-path=\"url(#p392ca249e8)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_12\">\n      <defs>\n       <path id=\"m13c6e41700\" d=\"M 0 0 \nL -3.5 0 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#m13c6e41700\" x=\"30.103125\" y=\"149.599219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_7\">\n      <!-- 0.0 -->\n      <g transform=\"translate(7.2 153.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \nQ 1547 4250 1301 3770 \nQ 1056 3291 1056 2328 \nQ 1056 1369 1301 889 \nQ 1547 409 2034 409 \nQ 2525 409 2770 889 \nQ 3016 1369 3016 2328 \nQ 3016 3291 2770 3770 \nQ 2525 4250 2034 4250 \nz\nM 2034 4750 \nQ 2819 4750 3233 4129 \nQ 3647 3509 3647 2328 \nQ 3647 1150 3233 529 \nQ 2819 -91 2034 -91 \nQ 1250 -91 836 529 \nQ 422 1150 422 2328 \nQ 422 3509 836 4129 \nQ 1250 4750 2034 4750 \nz\n\" transform=\"scale(0.015625)\"/>\n        <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-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_2\">\n     <g id=\"line2d_13\">\n      <path d=\"M 30.103125 121.879219 \nL 225.403125 121.879219 \n\" clip-path=\"url(#p392ca249e8)\" 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=\"#m13c6e41700\" x=\"30.103125\" y=\"121.879219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_8\">\n      <!-- 0.2 -->\n      <g transform=\"translate(7.2 125.678438) 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>\n    <g id=\"ytick_3\">\n     <g id=\"line2d_15\">\n      <path d=\"M 30.103125 94.159219 \nL 225.403125 94.159219 \n\" clip-path=\"url(#p392ca249e8)\" 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=\"#m13c6e41700\" x=\"30.103125\" y=\"94.159219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_9\">\n      <!-- 0.4 -->\n      <g transform=\"translate(7.2 97.958438) 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-34\" transform=\"translate(95.410156 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_4\">\n     <g id=\"line2d_17\">\n      <path d=\"M 30.103125 66.439219 \nL 225.403125 66.439219 \n\" clip-path=\"url(#p392ca249e8)\" 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=\"#m13c6e41700\" x=\"30.103125\" y=\"66.439219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_10\">\n      <!-- 0.6 -->\n      <g transform=\"translate(7.2 70.238437) 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 id=\"ytick_5\">\n     <g id=\"line2d_19\">\n      <path d=\"M 30.103125 38.719219 \nL 225.403125 38.719219 \n\" clip-path=\"url(#p392ca249e8)\" 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=\"#m13c6e41700\" x=\"30.103125\" y=\"38.719219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_11\">\n      <!-- 0.8 -->\n      <g transform=\"translate(7.2 42.518438) 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-30\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-38\" transform=\"translate(95.410156 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_6\">\n     <g id=\"line2d_21\">\n      <path d=\"M 30.103125 10.999219 \nL 225.403125 10.999219 \n\" clip-path=\"url(#p392ca249e8)\" 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=\"#m13c6e41700\" x=\"30.103125\" y=\"10.999219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_12\">\n      <!-- 1.0 -->\n      <g transform=\"translate(7.2 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>\n   <g id=\"line2d_23\">\n    <path d=\"M 30.921886 -1 \nL 38.719301 59.891826 \nL 47.335478 62.566565 \nL 55.951654 66.750084 \nL 64.567831 65.682127 \nL 73.184007 66.060466 \nL 78.928125 67.283804 \nL 87.544301 79.270015 \nL 96.160478 81.937804 \nL 104.776654 80.385925 \nL 113.392831 81.639763 \nL 122.009007 81.685527 \nL 127.753125 82.06438 \nL 136.369301 93.159765 \nL 144.985478 90.362917 \nL 153.601654 90.773616 \nL 162.217831 91.41445 \nL 170.834007 91.162906 \nL 176.578125 92.046303 \nL 185.194301 100.412602 \nL 193.810478 97.798046 \nL 202.426654 98.22164 \nL 211.042831 98.876399 \nL 219.659007 97.384458 \nL 225.403125 98.303575 \n\" clip-path=\"url(#p392ca249e8)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n   </g>\n   <g id=\"line2d_24\">\n    <path d=\"M -1 57.763588 \nL 7.126654 52.81886 \nL 15.742831 50.0035 \nL 24.359007 47.594051 \nL 30.103125 46.664073 \nL 38.719301 35.987415 \nL 47.335478 35.738197 \nL 55.951654 34.463006 \nL 64.567831 34.888277 \nL 73.184007 34.922622 \nL 78.928125 34.578395 \nL 87.544301 32.205129 \nL 96.160478 31.429261 \nL 104.776654 31.939042 \nL 113.392831 31.653294 \nL 122.009007 31.551033 \nL 127.753125 31.46459 \nL 136.369301 28.810272 \nL 144.985478 29.719183 \nL 153.601654 29.445224 \nL 162.217831 29.253583 \nL 170.834007 29.299856 \nL 176.578125 29.054285 \nL 185.194301 26.893003 \nL 193.810478 27.753515 \nL 202.426654 27.728019 \nL 211.042831 27.364517 \nL 219.659007 27.814659 \nL 225.403125 27.479089 \n\" clip-path=\"url(#p392ca249e8)\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #bf00bf; stroke-width: 1.5\"/>\n   </g>\n   <g id=\"line2d_25\">\n    <path d=\"M 30.103125 37.54362 \nL 78.928125 34.944541 \nL 127.753125 33.832864 \nL 176.578125 33.260959 \nL 225.403125 32.327671 \n\" clip-path=\"url(#p392ca249e8)\" 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=\"patch_3\">\n    <path d=\"M 30.103125 149.599219 \nL 30.103125 10.999219 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_4\">\n    <path d=\"M 225.403125 149.599219 \nL 225.403125 10.999219 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_5\">\n    <path d=\"M 30.103125 149.599219 \nL 225.403125 149.599219 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_6\">\n    <path d=\"M 30.103125 10.999219 \nL 225.403125 10.999219 \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 37.103125 144.599219 \nL 114.871875 144.599219 \nQ 116.871875 144.599219 116.871875 142.599219 \nL 116.871875 99.564844 \nQ 116.871875 97.564844 114.871875 97.564844 \nL 37.103125 97.564844 \nQ 35.103125 97.564844 35.103125 99.564844 \nL 35.103125 142.599219 \nQ 35.103125 144.599219 37.103125 144.599219 \nz\n\" style=\"fill: #ffffff; opacity: 0.8; stroke: #cccccc; stroke-linejoin: miter\"/>\n    </g>\n    <g id=\"line2d_26\">\n     <path d=\"M 39.103125 105.663281 \nL 49.103125 105.663281 \nL 59.103125 105.663281 \n\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n    </g>\n    <g id=\"text_13\">\n     <!-- train loss -->\n     <g transform=\"translate(67.103125 109.163281) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"DejaVuSans-74\" d=\"M 1172 4494 \nL 1172 3500 \nL 2356 3500 \nL 2356 3053 \nL 1172 3053 \nL 1172 1153 \nQ 1172 725 1289 603 \nQ 1406 481 1766 481 \nL 2356 481 \nL 2356 0 \nL 1766 0 \nQ 1100 0 847 248 \nQ 594 497 594 1153 \nL 594 3053 \nL 172 3053 \nL 172 3500 \nL 594 3500 \nL 594 4494 \nL 1172 4494 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-72\" d=\"M 2631 2963 \nQ 2534 3019 2420 3045 \nQ 2306 3072 2169 3072 \nQ 1681 3072 1420 2755 \nQ 1159 2438 1159 1844 \nL 1159 0 \nL 581 0 \nL 581 3500 \nL 1159 3500 \nL 1159 2956 \nQ 1341 3275 1631 3429 \nQ 1922 3584 2338 3584 \nQ 2397 3584 2469 3576 \nQ 2541 3569 2628 3553 \nL 2631 2963 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-61\" d=\"M 2194 1759 \nQ 1497 1759 1228 1600 \nQ 959 1441 959 1056 \nQ 959 750 1161 570 \nQ 1363 391 1709 391 \nQ 2188 391 2477 730 \nQ 2766 1069 2766 1631 \nL 2766 1759 \nL 2194 1759 \nz\nM 3341 1997 \nL 3341 0 \nL 2766 0 \nL 2766 531 \nQ 2569 213 2275 61 \nQ 1981 -91 1556 -91 \nQ 1019 -91 701 211 \nQ 384 513 384 1019 \nQ 384 1609 779 1909 \nQ 1175 2209 1959 2209 \nL 2766 2209 \nL 2766 2266 \nQ 2766 2663 2505 2880 \nQ 2244 3097 1772 3097 \nQ 1472 3097 1187 3025 \nQ 903 2953 641 2809 \nL 641 3341 \nQ 956 3463 1253 3523 \nQ 1550 3584 1831 3584 \nQ 2591 3584 2966 3190 \nQ 3341 2797 3341 1997 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-69\" d=\"M 603 3500 \nL 1178 3500 \nL 1178 0 \nL 603 0 \nL 603 3500 \nz\nM 603 4863 \nL 1178 4863 \nL 1178 4134 \nL 603 4134 \nL 603 4863 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-6e\" d=\"M 3513 2113 \nL 3513 0 \nL 2938 0 \nL 2938 2094 \nQ 2938 2591 2744 2837 \nQ 2550 3084 2163 3084 \nQ 1697 3084 1428 2787 \nQ 1159 2491 1159 1978 \nL 1159 0 \nL 581 0 \nL 581 3500 \nL 1159 3500 \nL 1159 2956 \nQ 1366 3272 1645 3428 \nQ 1925 3584 2291 3584 \nQ 2894 3584 3203 3211 \nQ 3513 2838 3513 2113 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-20\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-6c\" d=\"M 603 4863 \nL 1178 4863 \nL 1178 0 \nL 603 0 \nL 603 4863 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-73\" d=\"M 2834 3397 \nL 2834 2853 \nQ 2591 2978 2328 3040 \nQ 2066 3103 1784 3103 \nQ 1356 3103 1142 2972 \nQ 928 2841 928 2578 \nQ 928 2378 1081 2264 \nQ 1234 2150 1697 2047 \nL 1894 2003 \nQ 2506 1872 2764 1633 \nQ 3022 1394 3022 966 \nQ 3022 478 2636 193 \nQ 2250 -91 1575 -91 \nQ 1294 -91 989 -36 \nQ 684 19 347 128 \nL 347 722 \nQ 666 556 975 473 \nQ 1284 391 1588 391 \nQ 1994 391 2212 530 \nQ 2431 669 2431 922 \nQ 2431 1156 2273 1281 \nQ 2116 1406 1581 1522 \nL 1381 1569 \nQ 847 1681 609 1914 \nQ 372 2147 372 2553 \nQ 372 3047 722 3315 \nQ 1072 3584 1716 3584 \nQ 2034 3584 2315 3537 \nQ 2597 3491 2834 3397 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#DejaVuSans-74\"/>\n      <use xlink:href=\"#DejaVuSans-72\" transform=\"translate(39.208984 0)\"/>\n      <use xlink:href=\"#DejaVuSans-61\" transform=\"translate(80.322266 0)\"/>\n      <use xlink:href=\"#DejaVuSans-69\" transform=\"translate(141.601562 0)\"/>\n      <use xlink:href=\"#DejaVuSans-6e\" transform=\"translate(169.384766 0)\"/>\n      <use xlink:href=\"#DejaVuSans-20\" transform=\"translate(232.763672 0)\"/>\n      <use xlink:href=\"#DejaVuSans-6c\" transform=\"translate(264.550781 0)\"/>\n      <use xlink:href=\"#DejaVuSans-6f\" transform=\"translate(292.333984 0)\"/>\n      <use xlink:href=\"#DejaVuSans-73\" transform=\"translate(353.515625 0)\"/>\n      <use xlink:href=\"#DejaVuSans-73\" transform=\"translate(405.615234 0)\"/>\n     </g>\n    </g>\n    <g id=\"line2d_27\">\n     <path d=\"M 39.103125 120.341406 \nL 49.103125 120.341406 \nL 59.103125 120.341406 \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_14\">\n     <!-- train acc -->\n     <g transform=\"translate(67.103125 123.841406) scale(0.1 -0.1)\">\n      <use xlink:href=\"#DejaVuSans-74\"/>\n      <use xlink:href=\"#DejaVuSans-72\" transform=\"translate(39.208984 0)\"/>\n      <use xlink:href=\"#DejaVuSans-61\" transform=\"translate(80.322266 0)\"/>\n      <use xlink:href=\"#DejaVuSans-69\" transform=\"translate(141.601562 0)\"/>\n      <use xlink:href=\"#DejaVuSans-6e\" transform=\"translate(169.384766 0)\"/>\n      <use xlink:href=\"#DejaVuSans-20\" transform=\"translate(232.763672 0)\"/>\n      <use xlink:href=\"#DejaVuSans-61\" transform=\"translate(264.550781 0)\"/>\n      <use xlink:href=\"#DejaVuSans-63\" transform=\"translate(325.830078 0)\"/>\n      <use xlink:href=\"#DejaVuSans-63\" transform=\"translate(380.810547 0)\"/>\n     </g>\n    </g>\n    <g id=\"line2d_28\">\n     <path d=\"M 39.103125 135.019531 \nL 49.103125 135.019531 \nL 59.103125 135.019531 \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_15\">\n     <!-- test acc -->\n     <g transform=\"translate(67.103125 138.519531) scale(0.1 -0.1)\">\n      <use xlink:href=\"#DejaVuSans-74\"/>\n      <use xlink:href=\"#DejaVuSans-65\" transform=\"translate(39.208984 0)\"/>\n      <use xlink:href=\"#DejaVuSans-73\" transform=\"translate(100.732422 0)\"/>\n      <use xlink:href=\"#DejaVuSans-74\" transform=\"translate(152.832031 0)\"/>\n      <use xlink:href=\"#DejaVuSans-20\" transform=\"translate(192.041016 0)\"/>\n      <use xlink:href=\"#DejaVuSans-61\" transform=\"translate(223.828125 0)\"/>\n      <use xlink:href=\"#DejaVuSans-63\" transform=\"translate(285.107422 0)\"/>\n      <use xlink:href=\"#DejaVuSans-63\" transform=\"translate(340.087891 0)\"/>\n     </g>\n    </g>\n   </g>\n  </g>\n </g>\n <defs>\n  <clipPath id=\"p392ca249e8\">\n   <rect x=\"30.103125\" y=\"10.999219\" width=\"195.3\" height=\"138.6\"/>\n  </clipPath>\n </defs>\n</svg>\n"
     },
     "metadata": {}
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=fcn-md-13 fw=all -->\n",
    "\n",
    "## Prediction\n",
    "\n",
    "\n",
    "When predicting, we need to standardize the input image\n",
    "in each channel and transform the image into the four-dimensional input format required by the CNN."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "fcn-prediction-1"
   },
   "source": [
    "def predict(img):\n",
    "    X = test_iter._dataset.normalize_image(img)\n",
    "    X = np.expand_dims(X.transpose(2, 0, 1), axis=0)\n",
    "    pred = net(X.as_in_ctx(devices[0])).argmax(axis=1)\n",
    "    return pred.reshape(pred.shape[1], pred.shape[2])"
   ],
   "execution_count": 13,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=fcn-md-14 fw=all -->\n",
    "\n",
    "To visualize the predicted class of each pixel, we map the predicted class back to its label color in the dataset."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "fcn-prediction-2"
   },
   "source": [
    "def label2image(pred):\n",
    "    colormap = np.array(d2l.VOC_COLORMAP, ctx=devices[0], dtype='uint8')\n",
    "    X = pred.astype('int32')\n",
    "    return colormap[X, :]"
   ],
   "execution_count": 14,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=fcn-md-15 fw=all -->\n",
    "\n",
    "Images in the test dataset vary in size and shape.\n",
    "Since the model uses a transposed convolutional layer with stride of 32,\n",
    "when the height or width of an input image is indivisible by 32,\n",
    "the output height or width of the\n",
    "transposed convolutional layer will deviate from the shape of the input image.\n",
    "In order to address this issue,\n",
    "we can crop multiple rectangular areas with height and width that are integer multiples of 32 in the image,\n",
    "and perform forward propagation\n",
    "on the pixels in these areas separately.\n",
    "Note that\n",
    "the union of these rectangular areas needs to completely cover the input image.\n",
    "When a pixel is covered by multiple rectangular areas,\n",
    "the average of the transposed convolution outputs\n",
    "in separate areas for this same pixel\n",
    "can be input to\n",
    "the softmax operation\n",
    "to predict the class.\n",
    "\n",
    "\n",
    "For simplicity, we only read a few larger test images,\n",
    "and crop a $320\\times480$ area for prediction starting from the upper-left corner of an image.\n",
    "For these test images, we\n",
    "print their cropped areas,\n",
    "prediction results,\n",
    "and ground-truth row by row."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "fcn-prediction-3"
   },
   "source": [
    "voc_dir = d2l.download_extract('voc2012', 'VOCdevkit/VOC2012')\n",
    "test_images, test_labels = d2l.read_voc_images(voc_dir, False)\n",
    "n, imgs = 4, []\n",
    "for i in range(n):\n",
    "    crop_rect = (0, 0, 480, 320)\n",
    "    X = image.fixed_crop(test_images[i], *crop_rect)\n",
    "    pred = label2image(predict(X))\n",
    "    imgs += [X, pred, image.fixed_crop(test_labels[i], *crop_rect)]\n",
    "d2l.show_images(imgs[::3] + imgs[1::3] + imgs[2::3], 3, n, scale=2);"
   ],
   "execution_count": 15,
   "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=\"460.8pt\" height=\"313.900358pt\" viewBox=\"0 0 460.8 313.900358\" 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:21:25.426446</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 313.900358 \nL 460.8 313.900358 \nL 460.8 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 71.895652 \nL 104.243478 71.895652 \nL 104.243478 7.2 \nL 7.2 7.2 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#p62d1118e8b)\">\n    <image xlink:href=\"data:image/png;base64,\[encoded data, 23105 characters]\" id=\"imagef94c30f259\" transform=\"scale(1 -1) translate(0 -64.8)\" x=\"7.2\" y=\"-7.095652\" width=\"97.2\" height=\"64.8\"/>\n   </g>\n   <g id=\"patch_3\">\n    <path d=\"M 7.2 71.895652 \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 104.243478 71.895652 \nL 104.243478 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 71.895652 \nL 104.243478 71.895652 \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 104.243478 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 123.652174 71.895652 \nL 220.695652 71.895652 \nL 220.695652 7.2 \nL 123.652174 7.2 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#pa7306310b3)\">\n    <image xlink:href=\"data:image/png;base64,\[encoded data, 31713 characters]\" id=\"imagee11bb11f9c\" transform=\"scale(1 -1) translate(0 -64.8)\" x=\"123.652174\" y=\"-7.095652\" width=\"97.2\" height=\"64.8\"/>\n   </g>\n   <g id=\"patch_8\">\n    <path d=\"M 123.652174 71.895652 \nL 123.652174 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 220.695652 71.895652 \nL 220.695652 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 123.652174 71.895652 \nL 220.695652 71.895652 \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 123.652174 7.2 \nL 220.695652 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 240.104348 71.895652 \nL 337.147826 71.895652 \nL 337.147826 7.2 \nL 240.104348 7.2 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#pf536e6696b)\">\n    <image xlink:href=\"data:image/png;base64,\[encoded data, 30161 characters]\" id=\"image875f62adaa\" transform=\"scale(1 -1) translate(0 -64.8)\" x=\"240.104348\" y=\"-7.095652\" width=\"97.2\" height=\"64.8\"/>\n   </g>\n   <g id=\"patch_13\">\n    <path d=\"M 240.104348 71.895652 \nL 240.104348 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 337.147826 71.895652 \nL 337.147826 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 240.104348 71.895652 \nL 337.147826 71.895652 \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 240.104348 7.2 \nL 337.147826 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 356.556522 71.895652 \nL 453.6 71.895652 \nL 453.6 7.2 \nL 356.556522 7.2 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#p12f1172e4a)\">\n    <image xlink:href=\"data:image/png;base64,\[encoded data, 23709 characters]\" id=\"image5596fdcdbe\" transform=\"scale(1 -1) translate(0 -64.8)\" x=\"356.556522\" y=\"-7.095652\" width=\"97.2\" height=\"64.8\"/>\n   </g>\n   <g id=\"patch_18\">\n    <path d=\"M 356.556522 71.895652 \nL 356.556522 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 453.6 71.895652 \nL 453.6 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 356.556522 71.895652 \nL 453.6 71.895652 \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 356.556522 7.2 \nL 453.6 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 7.2 189.298005 \nL 104.243478 189.298005 \nL 104.243478 124.602353 \nL 7.2 124.602353 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#p85aa383b22)\">\n    <image xlink:href=\"data:image/png;base64,\niVBORw0KGgoAAAANSUhEUgAAAIcAAABaCAYAAACSR0X7AAAFP0lEQVR4nO3cS28bVRjG8b8dO03cW4jDpUhpQ1qEoKhQBFJpVUWBBargE7Duio+GxAbUHYsiugBFQlykiCJolaYp9JIqKaFJcONh8c6RTeI3sePxXNrnJ40U2Y58ZvLMmTNz3pMSECHSQTnrBkh+KRziUjjEpXCIS+EQl8IhLoVDXAqHuBQOcSkc4lI4xKVwiEvhEJfCIS6FQ1wKh7gUDnEpHOJSOMSlcAxAtVbLugmJUDgSVK5WmZqd5Z3Ll3nxzJmsm9M3hSNBUzMznLh4kdHxcU5dusRovZ51k/pSSfsLh4A68CrwEvAIuAXcBh5T7HUSm3Nz1Gs1NiYnqc3Pc2R1lfWsG9WHEin8PUaACeA48BoWiuH4ywGawN/APeA6cANYiV8vghHgbeACcAhoVquUGw3WgG+AHyjOvrRLNBzleDsM1IBJ4ARwDDtoQ7QC4YmADWAJ+BXrVZrAevx60Eyy4ftUBU4C57F97bRvT4BfgKvAamotS8a+w1HBzpjnsTC8HG/DwFj8fjdh2E2EHVyAf/h/OB5gvc0a1ts86ON7elUBTgHnsFAM7fH5CLt8fosF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aC4FA5xKRziUjjEpXCIS+EQl8IhLoVDXAqHuBQOcSkc4lI4xKVwiEvhEJfCIS6FQ1wKh7gUDnEpHOJSOMSlcIhL4RCXwiEuhUNcCoe4FA5xKRziUjjEpXCIS+EQl8IhLoVDXP8Bj1MZBf0rnsgAAAAASUVORK5CYII=\" id=\"imagefcdb819ea3\" transform=\"scale(1 -1) translate(0 -64.8)\" x=\"7.2\" y=\"-124.498005\" width=\"97.2\" height=\"64.8\"/>\n   </g>\n   <g id=\"patch_23\">\n    <path d=\"M 7.2 189.298005 \nL 7.2 124.602353 \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 104.243478 189.298005 \nL 104.243478 124.602353 \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 7.2 189.298005 \nL 104.243478 189.298005 \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 7.2 124.602353 \nL 104.243478 124.602353 \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 123.652174 189.298005 \nL 220.695652 189.298005 \nL 220.695652 124.602353 \nL 123.652174 124.602353 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#p5af504182d)\">\n    <image xlink:href=\"data:image/png;base64,\niVBORw0KGgoAAAANSUhEUgAAAIcAAABaCAYAAACSR0X7AAAKkElEQVR4nO2de2xb1R3HP9evOM+mzTvQpqQpLbTrA9rCYFCgoxTariigwQaMMdA2xLRpnfZgoAlpTCsTm8SmIe2vTTAQk8bWMjRGH1Mpj4lBoeojfd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rcCE6XzG43MlfE1yVbsB/sXcYHw2tRbq+x/c7j+WxC1XAYInFtbyQCPT2flsu4Q+pyuSgrK6OmpobOzk76+vpQE2R5jf9CzBCSjsfoxCCHMzbLzMDvO9wvzapyOKG4BKqrobISamqMVywSgdOnRRQAvb0wGJe/OxqFoaGpE4eNebDg5Dcbo9jisNHFFoeNLrY4bHSxxWGjiy0OG11scdjoYovDRhdbHDa62OKw0cUWh40u/wf6Z1rIFR/9MAAAAABJRU5ErkJggg==\" id=\"imagea02bf2b7d1\" transform=\"scale(1 -1) translate(0 -64.8)\" x=\"123.652174\" y=\"-124.498005\" width=\"97.2\" height=\"64.8\"/>\n   </g>\n   <g id=\"patch_28\">\n    <path d=\"M 123.652174 189.298005 \nL 123.652174 124.602353 \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 220.695652 189.298005 \nL 220.695652 124.602353 \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 123.652174 189.298005 \nL 220.695652 189.298005 \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 123.652174 124.602353 \nL 220.695652 124.602353 \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 240.104348 189.298005 \nL 337.147826 189.298005 \nL 337.147826 124.602353 \nL 240.104348 124.602353 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#p1a615d2695)\">\n    <image xlink:href=\"data:image/png;base64,\niVBORw0KGgoAAAANSUhEUgAAAIcAAABaCAYAAACSR0X7AAADSUlEQVR4n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41BkHIqMQ5FxKDIORcahyDgUvQVYNlDaari+cAAAAABJRU5ErkJggg==\" id=\"imagee35cdfca7f\" transform=\"scale(1 -1) translate(0 -64.8)\" x=\"240.104348\" y=\"-124.498005\" width=\"97.2\" height=\"64.8\"/>\n   </g>\n   <g id=\"patch_33\">\n    <path d=\"M 240.104348 189.298005 \nL 240.104348 124.602353 \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 337.147826 189.298005 \nL 337.147826 124.602353 \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 240.104348 189.298005 \nL 337.147826 189.298005 \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 240.104348 124.602353 \nL 337.147826 124.602353 \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 356.556522 189.298005 \nL 453.6 189.298005 \nL 453.6 124.602353 \nL 356.556522 124.602353 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#pd018228377)\">\n    <image xlink:href=\"data:image/png;base64,\niVBORw0KGgoAAAANSUhEUgAAAIcAAABaCAYAAACSR0X7AAAKVUlEQVR4nO2dWWxU1xmAvztj43UwNraFY0zNatfYJGYtWZQSSCGJkhR1U9UqVfuSp1aVWqV9iNT2MVLVhaiVUKsKaKgaCGsUIHVNWEtcp4QlDgYMxAvGeME22OPxMvf04bfFNhfPPveOzyeNMIPnzo/n81n/818DUGg0AXAlOgCNfdFyaCzRcmgs0XJoLNFyaCzRcmgs0XJoLNFyaCzRcmgs0XJoLElJdABOI3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47dDdLy6KFiB6OlkMTWxw15tDEFy2HxhIth8YSLYfGEi2HxhIth8YSLYfGEi2HxhIth8YSLYfGkv8D3WlQOSqYa7cAAAAASUVORK5CYII=\" id=\"imageb4a5d14878\" transform=\"scale(1 -1) translate(0 -64.8)\" x=\"356.556522\" y=\"-124.498005\" width=\"97.2\" height=\"64.8\"/>\n   </g>\n   <g id=\"patch_38\">\n    <path d=\"M 356.556522 189.298005 \nL 356.556522 124.602353 \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 453.6 189.298005 \nL 453.6 124.602353 \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 356.556522 189.298005 \nL 453.6 189.298005 \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 356.556522 124.602353 \nL 453.6 124.602353 \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 7.2 306.700358 \nL 104.243478 306.700358 \nL 104.243478 242.004706 \nL 7.2 242.004706 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#pfc11e69c20)\">\n    <image xlink:href=\"data:image/png;base64,\[encoded data, 6493 characters]\" id=\"imagec8bc73c7b0\" transform=\"scale(1 -1) translate(0 -64.8)\" x=\"7.2\" y=\"-241.900358\" width=\"97.2\" height=\"64.8\"/>\n   </g>\n   <g id=\"patch_43\">\n    <path d=\"M 7.2 306.700358 \nL 7.2 242.004706 \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 104.243478 306.700358 \nL 104.243478 242.004706 \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 7.2 306.700358 \nL 104.243478 306.700358 \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 7.2 242.004706 \nL 104.243478 242.004706 \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 123.652174 306.700358 \nL 220.695652 306.700358 \nL 220.695652 242.004706 \nL 123.652174 242.004706 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#p5f4ff8fa99)\">\n    <image xlink:href=\"data:image/png;base64,\[encoded data, 7233 characters]\" id=\"image70f2a846cb\" transform=\"scale(1 -1) translate(0 -64.8)\" x=\"123.652174\" y=\"-241.900358\" width=\"97.2\" height=\"64.8\"/>\n   </g>\n   <g id=\"patch_48\">\n    <path d=\"M 123.652174 306.700358 \nL 123.652174 242.004706 \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 220.695652 306.700358 \nL 220.695652 242.004706 \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 123.652174 306.700358 \nL 220.695652 306.700358 \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 123.652174 242.004706 \nL 220.695652 242.004706 \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 240.104348 306.700358 \nL 337.147826 306.700358 \nL 337.147826 242.004706 \nL 240.104348 242.004706 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#p30e84c13d3)\">\n    <image xlink:href=\"data:image/png;base64,\niVBORw0KGgoAAAANSUhEUgAAAIcAAABaCAYAAACSR0X7AAAK40lEQVR4nO3de2wUdQLA8e/Mbruvvgt0224ftFgoUDhQjBAUoVZietELaU4uQTEqQoqIKIQQ5cQT5EQ9EDGKQlCRw6BH1CPgSYwiXsEer4KUtkdXQKCl2wd97W73MXN/9CwCHeluS7uU3yfpH7t0fjtlv92Z+c12RwJUBKETcl+vgBC6RByCJhGHoEnEIWgScQiaRByCJhGHoEnEIWgScQiaRByCJn1fr4CgTZZlDIZwJCn4MdravPj9/qCWFXH0MkmSkGWJ2NhoEhMHkpaW3PFvNpuVzMzUjtsREWaysjK69XjffVfMihVv4/P5Al9XxIm360ankzGZjAwaFI/NZmX06GGkpiaRnm4jOTkRvd5ETY2C260AoCgqR4404XQqHWOUl7fgcHiDenybzcDSpWk89NB8SktPBry8eOXoAZIkodPJDBgQi9U6kMzMVLKzM8nMTCUjIw2z2UJrq47Tp9uorm7jk08aqa09T3l5K3V1XrzeSzEEuQXoVGmpjqeeSiMtLUnE0ZskSSI7O5MxY4YzblwO6ek2rNZBSJKRqio/9fVeDh5s4sMPHdTUnOPMGRcul4LP13sv1G63n/JyJ1lZg9m167uAlxdxBOmeeyawYsVi6upkSkqa+OCDRmprz1JR0UpDgxevV0Xt4w22ooDD4SE7OxNJklADXCERB+2vAtHREchy50f2Ho+PlpbWjtsWi4knn5zBjh1NrFpl79hnCEWHDjXyxBNJGI0GXC53QMveNHGEh4cRHh5GcnICVutAMjJSSE5OIDMzFVmWychIQ5I6/+9wu1v5+efzAPh8fg4fLsVm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soK7Wpq6pg37y8MHTqYEycquXixucvLijhuAvX1jezbdyTg5cRmRdAk4hA0iTgETSIOQZOIQ9Ak4hA0iTgETSKOEOf3q9hs1j55bBFHiDt4sJHBg20d7wrrTSKOENcXfxfzCxGHoEnEIWgScQiaRByCJhGHoEnEIWgScQiaRByCJhGHoEnEIWgScQiaRBwhSlVVrFZDt67S1F0ijhB16NBxhgwxI8t9V4eII0S1tFzfD6LrChGHoEnEIWgScQiaRBw3ALPZRFhY7/9Zs4gjROh0Omw2K5GRl3/gvt3uJDExkejoyF5fJxFHiCgomMoXX7zHunUvYLGYOu6vq/Pg9yPeYHwzs9kS0euNjB37O+bOnYFO1/dPTd+vgQC0f66pw1HNhQteHnzwAaZMGc/AgeEdn7bcF0QcIaK62sFrr20gLk7ip5/8TJ48npgYPRaLrs/WScQRQnbv/p7du78hNjYMu92neZ3b3iLiCCE+n581a97H6TxLW5ty3a/lci0ijhBTVeVg5cq3yczUceBAI05nD1/eMgAijhC0f38J27b9k0mTYgny2n09QsQRghRFYdu2nURGKkREiB1S4Qoej7fb12jrLhGHoEnEIWgScQiaRByCJhGHoEnEIWgScYQwSfrl8uN9Q8QRopxON83NDSxcOBjw4ff3/jS6RPtlIoUQNGxYBpMn38GJE5Xs2VPc65NiIg5Bk9isCJr+Byi4a2KlbDP1AAAAAElFTkSuQmCC\" id=\"imagea0cbe79f77\" transform=\"scale(1 -1) translate(0 -64.8)\" x=\"240.104348\" y=\"-241.900358\" width=\"97.2\" height=\"64.8\"/>\n   </g>\n   <g id=\"patch_53\">\n    <path d=\"M 240.104348 306.700358 \nL 240.104348 242.004706 \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 337.147826 306.700358 \nL 337.147826 242.004706 \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 240.104348 306.700358 \nL 337.147826 306.700358 \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 240.104348 242.004706 \nL 337.147826 242.004706 \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 356.556522 306.700358 \nL 453.6 306.700358 \nL 453.6 242.004706 \nL 356.556522 242.004706 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g clip-path=\"url(#pb2ebaae2cc)\">\n    <image xlink:href=\"data:image/png;base64,\[encoded data, 4677 characters]\" id=\"imagecd8acc1cdd\" transform=\"scale(1 -1) translate(0 -64.8)\" x=\"356.556522\" y=\"-241.900358\" width=\"97.2\" height=\"64.8\"/>\n   </g>\n   <g id=\"patch_58\">\n    <path d=\"M 356.556522 306.700358 \nL 356.556522 242.004706 \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 453.6 306.700358 \nL 453.6 242.004706 \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 356.556522 306.700358 \nL 453.6 306.700358 \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 356.556522 242.004706 \nL 453.6 242.004706 \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=\"p62d1118e8b\">\n   <rect x=\"7.2\" y=\"7.2\" width=\"97.043478\" height=\"64.695652\"/>\n  </clipPath>\n  <clipPath id=\"pa7306310b3\">\n   <rect x=\"123.652174\" y=\"7.2\" width=\"97.043478\" height=\"64.695652\"/>\n  </clipPath>\n  <clipPath id=\"pf536e6696b\">\n   <rect x=\"240.104348\" y=\"7.2\" width=\"97.043478\" height=\"64.695652\"/>\n  </clipPath>\n  <clipPath id=\"p12f1172e4a\">\n   <rect x=\"356.556522\" y=\"7.2\" width=\"97.043478\" height=\"64.695652\"/>\n  </clipPath>\n  <clipPath id=\"p85aa383b22\">\n   <rect x=\"7.2\" y=\"124.602353\" width=\"97.043478\" height=\"64.695652\"/>\n  </clipPath>\n  <clipPath id=\"p5af504182d\">\n   <rect x=\"123.652174\" y=\"124.602353\" width=\"97.043478\" height=\"64.695652\"/>\n  </clipPath>\n  <clipPath id=\"p1a615d2695\">\n   <rect x=\"240.104348\" y=\"124.602353\" width=\"97.043478\" height=\"64.695652\"/>\n  </clipPath>\n  <clipPath id=\"pd018228377\">\n   <rect x=\"356.556522\" y=\"124.602353\" width=\"97.043478\" height=\"64.695652\"/>\n  </clipPath>\n  <clipPath id=\"pfc11e69c20\">\n   <rect x=\"7.2\" y=\"242.004706\" width=\"97.043478\" height=\"64.695652\"/>\n  </clipPath>\n  <clipPath id=\"p5f4ff8fa99\">\n   <rect x=\"123.652174\" y=\"242.004706\" width=\"97.043478\" height=\"64.695652\"/>\n  </clipPath>\n  <clipPath id=\"p30e84c13d3\">\n   <rect x=\"240.104348\" y=\"242.004706\" width=\"97.043478\" height=\"64.695652\"/>\n  </clipPath>\n  <clipPath id=\"pb2ebaae2cc\">\n   <rect x=\"356.556522\" y=\"242.004706\" width=\"97.043478\" height=\"64.695652\"/>\n  </clipPath>\n </defs>\n</svg>\n"
     },
     "metadata": {}
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=fcn-md-16 fw=all -->\n",
    "\n",
    "## Summary\n",
    "\n",
    "* The fully convolutional network first uses a CNN to extract image features, then transforms the number of channels into the number of classes via a $1\\times 1$ convolutional layer, and finally transforms the height and width of the feature maps to those of the input image via the transposed convolution.\n",
    "* In a fully convolutional network, we can use upsampling of bilinear interpolation to initialize the transposed convolutional layer.\n",
    "\n",
    "\n",
    "## Exercises\n",
    "\n",
    "1. If we use Xavier initialization for the transposed convolutional layer in the experiment, how does the result change?\n",
    "1. Can you further improve the accuracy of the model by tuning the hyperparameters?\n",
    "1. Predict the classes of all pixels in test images.\n",
    "1. The original fully convolutional network paper also uses outputs of some intermediate CNN layers [@Long.Shelhamer.Darrell.2015]. Try to implement this idea."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=fcn-md-17 fw=mxnet -->\n",
    "\n",
    "[Discussions](https://d2l.discourse.group/t/377)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "name": "d2l-mxnet",
   "display_name": "d2l (MXNet)",
   "language": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
