Files
2024-09-25 18:29:02 +08:00

2388 lines
67 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{
"cells": [
{
"cell_type": "markdown",
"id": "f2160c1d-37bb-482b-a270-daa13c612f7c",
"metadata": {},
"source": [
"# 卷积神经网络\n",
"\n",
"目录\n",
"\n",
"- 图像卷积\n",
"- 填充和步幅\n",
"- 多输入多输出通道\n",
"- 池化层\n",
"- 卷积神经网络(LeNet)"
]
},
{
"cell_type": "markdown",
"id": "6846ad05-7209-4c31-9378-b9b532a3667e",
"metadata": {
"jp-MarkdownHeadingCollapsed": true,
"slideshow": {
"slide_type": "-"
},
"tags": []
},
"source": [
"## 图像卷积\n",
"\n",
"互相关运算"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "ac9478e0-6433-4cf7-917f-600f08edc110",
"metadata": {
"origin_pos": 3,
"tab": [
"pytorch"
]
},
"outputs": [],
"source": [
"import torch\n",
"from torch import nn\n",
"from d2l import torch as d2l\n",
"\n",
"def corr2d(X, K): \n",
" \"\"\"计算二维互相关运算\"\"\"\n",
" h, w = K.shape\n",
" Y = torch.zeros((X.shape[0] - h + 1, X.shape[1] - w + 1))\n",
" for i in range(Y.shape[0]):\n",
" for j in range(Y.shape[1]):\n",
" Y[i, j] = (X[i:i + h, j:j + w] * K).sum()\n",
" return Y"
]
},
{
"cell_type": "markdown",
"id": "314a155d-9475-4a87-950d-c14bbcad6d44",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"验证上述二维互相关运算的输出"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "3f8076da-f6b1-4b35-ba49-c31cb1314304",
"metadata": {
"origin_pos": 6,
"tab": [
"pytorch"
]
},
"outputs": [
{
"data": {
"text/plain": [
"tensor([[19., 25.],\n",
" [37., 43.]])"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"X = torch.tensor([[0.0, 1.0, 2.0], [3.0, 4.0, 5.0], [6.0, 7.0, 8.0]])\n",
"K = torch.tensor([[0.0, 1.0], [2.0, 3.0]])\n",
"corr2d(X, K)"
]
},
{
"cell_type": "markdown",
"id": "aab13ec8-679c-41b7-a686-98527d50a6f7",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"实现二维卷积层"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "8c2795ba-6b7e-4d65-a718-7834d515eebf",
"metadata": {
"origin_pos": 9,
"tab": [
"pytorch"
]
},
"outputs": [],
"source": [
"class Conv2D(nn.Module):\n",
" def __init__(self, kernel_size):\n",
" super().__init__()\n",
" self.weight = nn.Parameter(torch.rand(kernel_size))\n",
" self.bias = nn.Parameter(torch.zeros(1))\n",
"\n",
" def forward(self, x):\n",
" return corr2d(x, self.weight) + self.bias"
]
},
{
"cell_type": "markdown",
"id": "9a4b28c4-b74d-47f0-a549-2b2d7d350e55",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"卷积层的一个简单应用:\n",
"检测图像中不同颜色的边缘"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "2763c05e-3af6-48ab-8660-e7ffff81bbf5",
"metadata": {
"origin_pos": 12,
"tab": [
"pytorch"
]
},
"outputs": [
{
"data": {
"text/plain": [
"tensor([[1., 1., 0., 0., 0., 0., 1., 1.],\n",
" [1., 1., 0., 0., 0., 0., 1., 1.],\n",
" [1., 1., 0., 0., 0., 0., 1., 1.],\n",
" [1., 1., 0., 0., 0., 0., 1., 1.],\n",
" [1., 1., 0., 0., 0., 0., 1., 1.],\n",
" [1., 1., 0., 0., 0., 0., 1., 1.]])"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"X = torch.ones((6, 8))\n",
"X[:, 2:6] = 0\n",
"X"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "c3d67537-eb49-4136-b5bd-51cc13eaafb2",
"metadata": {
"origin_pos": 15,
"tab": [
"pytorch"
]
},
"outputs": [],
"source": [
"K = torch.tensor([[1.0, -1.0]])"
]
},
{
"cell_type": "markdown",
"id": "965ca956-b67c-451f-9dd4-8ab725165f1a",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"输出`Y`中的1代表从白色到黑色的边缘,-1代表从黑色到白色的边缘"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "5cf508d4-c35a-428d-9bb1-96fc32ae5864",
"metadata": {
"origin_pos": 17,
"tab": [
"pytorch"
]
},
"outputs": [
{
"data": {
"text/plain": [
"tensor([[ 0., 1., 0., 0., 0., -1., 0.],\n",
" [ 0., 1., 0., 0., 0., -1., 0.],\n",
" [ 0., 1., 0., 0., 0., -1., 0.],\n",
" [ 0., 1., 0., 0., 0., -1., 0.],\n",
" [ 0., 1., 0., 0., 0., -1., 0.],\n",
" [ 0., 1., 0., 0., 0., -1., 0.]])"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Y = corr2d(X, K)\n",
"Y"
]
},
{
"cell_type": "markdown",
"id": "7bc03775-24f6-4d2a-b2aa-e870717de626",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"卷积核`K`只可以检测垂直边缘"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "39d014be-40db-4d15-8caf-591a2710845c",
"metadata": {
"origin_pos": 19,
"tab": [
"pytorch"
]
},
"outputs": [
{
"data": {
"text/plain": [
"tensor([[0., 0., 0., 0., 0.],\n",
" [0., 0., 0., 0., 0.],\n",
" [0., 0., 0., 0., 0.],\n",
" [0., 0., 0., 0., 0.],\n",
" [0., 0., 0., 0., 0.],\n",
" [0., 0., 0., 0., 0.],\n",
" [0., 0., 0., 0., 0.],\n",
" [0., 0., 0., 0., 0.]])"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"corr2d(X.t(), K)"
]
},
{
"cell_type": "markdown",
"id": "87ad3bb5-f1b5-4788-9db8-2c1c27cffbfa",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"学习由`X`生成`Y`的卷积核"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dd75f3b8-6a8e-4956-8f9c-f39ac8ceb791",
"metadata": {
"origin_pos": 22,
"tab": [
"pytorch"
]
},
"outputs": [],
"source": [
"# 构造一个二维卷积层,它具有1个输出通道和形状为(1,2)的卷积核\n",
"conv2d = nn.Conv2d(1,1, kernel_size=(1, 2), bias=False)\n",
"\n",
"# 这个二维卷积层使用四维输入和输出格式(批量大小、通道、高度、宽度),\n",
"# 其中批量大小和通道数都为1\n",
"X = X.reshape((1, 1, 6, 8))\n",
"Y = Y.reshape((1, 1, 6, 7))\n",
"lr = 3e-2"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "0d28ad4a-bf04-4352-b0c4-c5d5ec11646a",
"metadata": {
"origin_pos": 22,
"slideshow": {
"slide_type": "slide"
},
"tab": [
"pytorch"
]
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"epoch 2, loss 8.836\n",
"epoch 4, loss 1.692\n",
"epoch 6, loss 0.370\n",
"epoch 8, loss 0.097\n",
"epoch 10, loss 0.031\n"
]
}
],
"source": [
"for i in range(10):\n",
" Y_hat = conv2d(X)\n",
" l = (Y_hat - Y) ** 2\n",
" conv2d.zero_grad()\n",
" l.sum().backward()\n",
" # 迭代更新卷积核\n",
" conv2d.weight.data[:] -= lr * conv2d.weight.grad\n",
" if (i + 1) % 2 == 0:\n",
" print(f'epoch {i+1}, loss {l.sum():.3f}')"
]
},
{
"cell_type": "markdown",
"id": "eaeb6855-12e3-40b0-acc8-71cadbf9f55e",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"所学的卷积核的权重张量"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "b473f6f7-6fca-4aa6-8c77-87c57b7f9b5b",
"metadata": {
"origin_pos": 26,
"tab": [
"pytorch"
]
},
"outputs": [
{
"data": {
"text/plain": [
"tensor([[ 1.0015, -0.9692]])"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"conv2d.weight.data.reshape((1, 2))"
]
},
{
"cell_type": "markdown",
"id": "5879af59-0af7-4128-a750-84d5ce60f25d",
"metadata": {
"jp-MarkdownHeadingCollapsed": true,
"slideshow": {
"slide_type": "-"
},
"tags": []
},
"source": [
"## 填充和步幅\n",
"\n",
"在所有侧边填充1个像素"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "979a995a-96f9-4d41-8442-2d32af9074bf",
"metadata": {
"origin_pos": 2,
"tab": [
"pytorch"
]
},
"outputs": [],
"source": [
"import torch\n",
"from torch import nn\n",
"\n",
"\n",
"def comp_conv2d(conv2d, X):\n",
" \"\"\"初始化卷积层权重,并对输入和输出提高和缩减相应的维数\"\"\"\n",
" X = X.reshape((1, 1) + X.shape) # 批量大小和通道数都是1\n",
" Y = conv2d(X)\n",
" return Y.reshape(Y.shape[2:]) # 省略前两个维度:批量大小和通道"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "f9f0ed64-7d08-4788-bf0b-932b9ec4803b",
"metadata": {
"origin_pos": 2,
"slideshow": {
"slide_type": "slide"
},
"tab": [
"pytorch"
]
},
"outputs": [
{
"data": {
"text/plain": [
"torch.Size([8, 8])"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 注意,每边都填充了1行或1列,因此总共添加了2行或2列\n",
"conv2d = nn.Conv2d(1, 1, kernel_size=3, padding=1)\n",
"X = torch.rand(size=(8, 8))\n",
"comp_conv2d(conv2d, X).shape"
]
},
{
"cell_type": "markdown",
"id": "cf74250e-eb1b-47df-9141-f931fafc3af0",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"填充不同的高度和宽度"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "545bfb03-c86e-4f29-9f2f-940c7ec49aaf",
"metadata": {
"origin_pos": 6,
"tab": [
"pytorch"
]
},
"outputs": [
{
"data": {
"text/plain": [
"torch.Size([8, 8])"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"conv2d = nn.Conv2d(1, 1, kernel_size=(5, 3), padding=(2, 1))\n",
"comp_conv2d(conv2d, X).shape"
]
},
{
"cell_type": "markdown",
"id": "6a8ce394-d251-438d-a6ad-0ae688a17a91",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"将高度和宽度的步幅设置为2"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "15d25626-14d6-49c2-a7d2-f5b32d4ae621",
"metadata": {
"origin_pos": 10,
"tab": [
"pytorch"
]
},
"outputs": [
{
"data": {
"text/plain": [
"torch.Size([4, 4])"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"conv2d = nn.Conv2d(1, 1, kernel_size=3, padding=1, stride=2)\n",
"comp_conv2d(conv2d, X).shape"
]
},
{
"cell_type": "markdown",
"id": "64f13f70-7ba6-4c68-adc4-951c77fb7b6c",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"一个稍微复杂的例子"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "7aae79d5-a75d-4769-bac5-52c0dd6c2cd4",
"metadata": {
"origin_pos": 14,
"tab": [
"pytorch"
]
},
"outputs": [
{
"data": {
"text/plain": [
"torch.Size([2, 2])"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"conv2d = nn.Conv2d(1, 1, kernel_size=(3, 5), padding=(0, 1), stride=(3, 4))\n",
"comp_conv2d(conv2d, X).shape"
]
},
{
"cell_type": "markdown",
"id": "b0ade0d5-8c2e-42d3-874d-bb9880c89dab",
"metadata": {
"jp-MarkdownHeadingCollapsed": true,
"slideshow": {
"slide_type": "-"
},
"tags": []
},
"source": [
"## 多输入多输出通道\n",
"\n",
"实现一下多输入通道互相关运算"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "9be9ab73-d95c-4a89-acfe-ac912e33e831",
"metadata": {
"origin_pos": 3,
"tab": [
"pytorch"
]
},
"outputs": [],
"source": [
"import torch\n",
"from d2l import torch as d2l\n",
"\n",
"def corr2d_multi_in(X, K):\n",
" # 先遍历“X”和“K”的第0个维度(通道维度,忽略批量),再把它们加在一起\n",
" return sum(d2l.corr2d(x, k) for x, k in zip(X, K))"
]
},
{
"cell_type": "markdown",
"id": "5cb1a6f4-9155-4c6e-b452-6f0575ac6bc3",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"验证互相关运算的输出"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "ffc69b60-744c-4a12-8f3c-ffb93993e6b8",
"metadata": {
"origin_pos": 6,
"tab": [
"pytorch"
]
},
"outputs": [
{
"data": {
"text/plain": [
"tensor([[ 56., 72.],\n",
" [104., 120.]])"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"X = torch.tensor([[[0.0, 1.0, 2.0], [3.0, 4.0, 5.0], [6.0, 7.0, 8.0]],\n",
" [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]])\n",
"K = torch.tensor([[[0.0, 1.0], [2.0, 3.0]], [[1.0, 2.0], [3.0, 4.0]]])\n",
"\n",
"corr2d_multi_in(X, K)"
]
},
{
"cell_type": "markdown",
"id": "2b26766f-0d38-4dec-b444-49564c7b1706",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"计算多个通道的输出的互相关函数"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "f973b848-4341-43b5-bdeb-dde75fc953e9",
"metadata": {
"origin_pos": 10,
"tab": [
"pytorch"
]
},
"outputs": [
{
"data": {
"text/plain": [
"torch.Size([3, 2, 2, 2])"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def corr2d_multi_in_out(X, K):\n",
" # 迭代“K”的第0个维度,每次都对输入“X”执行互相关运算。\n",
" # 最后将所有结果都叠加在一起\n",
" return torch.stack([corr2d_multi_in(X, k) for k in K], 0)\n",
"\n",
"K = torch.stack((K, K + 1, K + 2), 0)\n",
"K.shape"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "8a5ef08c-2688-4551-9fe4-4fe83476b568",
"metadata": {
"origin_pos": 12,
"slideshow": {
"slide_type": "slide"
},
"tab": [
"pytorch"
]
},
"outputs": [
{
"data": {
"text/plain": [
"tensor([[[ 56., 72.],\n",
" [104., 120.]],\n",
"\n",
" [[ 76., 100.],\n",
" [148., 172.]],\n",
"\n",
" [[ 96., 128.],\n",
" [192., 224.]]])"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"corr2d_multi_in_out(X, K)"
]
},
{
"cell_type": "markdown",
"id": "8b5646a7-4eaf-4c73-ae23-a6b0ae4b3667",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"1x1卷积"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fd63dcb7-8f02-46e9-8696-8cd24313460d",
"metadata": {
"origin_pos": 18,
"tab": [
"pytorch"
]
},
"outputs": [],
"source": [
"def corr2d_multi_in_out_1x1(X, K):\n",
" c_i, h, w = X.shape\n",
" c_o = K.shape[0]\n",
" X = X.reshape((c_i, h * w))\n",
" K = K.reshape((c_o, c_i))\n",
" # 全连接层中的矩阵乘法\n",
" Y = torch.matmul(K, X)\n",
" return Y.reshape((c_o, h, w))"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "18e97ece-4c09-4273-9e7b-a0934046c97c",
"metadata": {
"origin_pos": 18,
"slideshow": {
"slide_type": "slide"
},
"tab": [
"pytorch"
]
},
"outputs": [],
"source": [
"X = torch.normal(0, 1, (3, 3, 3))\n",
"K = torch.normal(0, 1, (2, 3, 1, 1))\n",
"\n",
"Y1 = corr2d_multi_in_out_1x1(X, K)\n",
"Y2 = corr2d_multi_in_out(X, K)\n",
"assert float(torch.abs(Y1 - Y2).sum()) < 1e-6"
]
},
{
"cell_type": "markdown",
"id": "64c48e4b-8c94-4de9-bd8d-e03512695e7e",
"metadata": {
"jp-MarkdownHeadingCollapsed": true,
"slideshow": {
"slide_type": "-"
},
"tags": []
},
"source": [
"## 池化层\n",
"\n",
"池化也有译成汇聚。实现池化层的前向传播"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "7ce8507e-5ba3-427a-9066-d1031580472d",
"metadata": {
"origin_pos": 3,
"tab": [
"pytorch"
]
},
"outputs": [],
"source": [
"import torch\n",
"from torch import nn\n",
"from d2l import torch as d2l\n",
"\n",
"def pool2d(X, pool_size, mode='max'):\n",
" p_h, p_w = pool_size\n",
" Y = torch.zeros((X.shape[0] - p_h + 1, X.shape[1] - p_w + 1))\n",
" for i in range(Y.shape[0]):\n",
" for j in range(Y.shape[1]):\n",
" if mode == 'max':\n",
" Y[i, j] = X[i: i + p_h, j: j + p_w].max()\n",
" elif mode == 'avg':\n",
" Y[i, j] = X[i: i + p_h, j: j + p_w].mean()\n",
" return Y"
]
},
{
"cell_type": "markdown",
"id": "fd4f9890-9159-4d0f-92bf-629c91f522ac",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"验证二维最大汇聚层的输出"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "4d6aca2f-7a2b-4e4e-a33f-51cfeabe3149",
"metadata": {
"origin_pos": 6,
"tab": [
"pytorch"
]
},
"outputs": [
{
"data": {
"text/plain": [
"tensor([[4., 5.],\n",
" [7., 8.]])"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"X = torch.tensor([[0.0, 1.0, 2.0], [3.0, 4.0, 5.0], [6.0, 7.0, 8.0]])\n",
"pool2d(X, (2, 2))"
]
},
{
"cell_type": "markdown",
"id": "da22e032-1759-4359-836e-36ecfd643583",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"source": [
"验证平均汇聚层"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "2939723a-f3ea-4f70-b291-cf5dbfd8fe30",
"metadata": {
"origin_pos": 8,
"tab": [
"pytorch"
]
},
"outputs": [
{
"data": {
"text/plain": [
"tensor([[2., 3.],\n",
" [5., 6.]])"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pool2d(X, (2, 2), 'avg')"
]
},
{
"cell_type": "markdown",
"id": "c0cb77fd-3e7b-4d1d-a616-63c6100d2feb",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"填充和步幅"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "a574a0ed-4184-4ad5-8f16-b802bea2bb99",
"metadata": {
"origin_pos": 11,
"tab": [
"pytorch"
]
},
"outputs": [
{
"data": {
"text/plain": [
"tensor([[[[ 0., 1., 2., 3.],\n",
" [ 4., 5., 6., 7.],\n",
" [ 8., 9., 10., 11.],\n",
" [12., 13., 14., 15.]]]])"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"X = torch.arange(16, dtype=torch.float32).reshape((1, 1, 4, 4))\n",
"X"
]
},
{
"cell_type": "markdown",
"id": "0209afc0-8eb4-4c58-a5c6-efdc1988e0fd",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"source": [
"深度学习框架中的步幅与汇聚窗口的大小相同"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "b66fd222-9233-4dc9-bbce-87925a86498b",
"metadata": {
"origin_pos": 15,
"tab": [
"pytorch"
]
},
"outputs": [
{
"data": {
"text/plain": [
"tensor([[[[10.]]]])"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pool2d = nn.MaxPool2d(3)\n",
"pool2d(X)"
]
},
{
"cell_type": "markdown",
"id": "0c169cd1-b0d6-4760-88e2-0ad530c51cfc",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"填充和步幅可以手动设定"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "4fdbb845-7f4b-4649-96c0-3c0300b6021a",
"metadata": {
"origin_pos": 19,
"tab": [
"pytorch"
]
},
"outputs": [
{
"data": {
"text/plain": [
"tensor([[[[ 5., 7.],\n",
" [13., 15.]]]])"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pool2d = nn.MaxPool2d(3, padding=1, stride=2)\n",
"pool2d(X)"
]
},
{
"cell_type": "markdown",
"id": "7b83b34f-526b-48b1-b5ff-963c84b57471",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"source": [
"设定一个任意大小的矩形汇聚窗口,并分别设定填充和步幅的高度和宽度"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "fc4d58c9-df77-4765-8344-948d66e9d55f",
"metadata": {
"origin_pos": 25,
"tab": [
"pytorch"
]
},
"outputs": [
{
"data": {
"text/plain": [
"tensor([[[[ 5., 7.],\n",
" [13., 15.]]]])"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pool2d = nn.MaxPool2d((2, 3), stride=(2, 3), padding=(0, 1))\n",
"pool2d(X)"
]
},
{
"cell_type": "markdown",
"id": "6a771a4c-bda2-48e6-bd31-d8d4eec503ad",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"汇聚层在每个输入通道上单独运算"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "8fc17adc-68a2-4395-8ca4-db4c853eae72",
"metadata": {
"origin_pos": 29,
"tab": [
"pytorch"
]
},
"outputs": [
{
"data": {
"text/plain": [
"tensor([[[[ 0., 1., 2., 3.],\n",
" [ 4., 5., 6., 7.],\n",
" [ 8., 9., 10., 11.],\n",
" [12., 13., 14., 15.]],\n",
"\n",
" [[ 1., 2., 3., 4.],\n",
" [ 5., 6., 7., 8.],\n",
" [ 9., 10., 11., 12.],\n",
" [13., 14., 15., 16.]]]])"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"X = torch.cat((X, X + 1), 1)\n",
"X"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "4622f1b6-0352-446f-8a67-c336f42249d2",
"metadata": {
"origin_pos": 33,
"tab": [
"pytorch"
]
},
"outputs": [
{
"data": {
"text/plain": [
"tensor([[[[ 5., 7.],\n",
" [13., 15.]],\n",
"\n",
" [[ 6., 8.],\n",
" [14., 16.]]]])"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pool2d = nn.MaxPool2d(3, padding=1, stride=2)\n",
"pool2d(X)"
]
},
{
"cell_type": "markdown",
"id": "a71866f9-e712-467a-9e0d-3832db22e4ad",
"metadata": {
"slideshow": {
"slide_type": "-"
},
"tags": []
},
"source": [
"## 卷积神经网络(LeNet)\n",
"\n",
"LeNet(LeNet-5)由两个部分组成:\n",
"卷积编码器和全连接层密集块"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "10bf89f8-9718-4d30-bceb-f64ccd57d7e8",
"metadata": {
"origin_pos": 2,
"tab": [
"pytorch"
]
},
"outputs": [],
"source": [
"import torch\n",
"from torch import nn\n",
"from d2l import torch as d2l\n",
"\n",
"net = nn.Sequential(\n",
" nn.Conv2d(1, 6, kernel_size=5, padding=2), nn.Sigmoid(),\n",
" nn.AvgPool2d(kernel_size=2, stride=2),\n",
" nn.Conv2d(6, 16, kernel_size=5), nn.Sigmoid(),\n",
" nn.AvgPool2d(kernel_size=2, stride=2),\n",
" nn.Flatten(),\n",
" nn.Linear(16 * 5 * 5, 120), nn.Sigmoid(),\n",
" nn.Linear(120, 84), nn.Sigmoid(),\n",
" nn.Linear(84, 10))"
]
},
{
"cell_type": "markdown",
"id": "b108595b-2b06-4670-b55e-4096d2c97e7d",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"检查模型"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "fca54cef-3f57-4901-b1e7-4039c9050a53",
"metadata": {
"origin_pos": 6,
"tab": [
"pytorch"
]
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Conv2d output shape: \t torch.Size([1, 6, 28, 28])\n",
"Sigmoid output shape: \t torch.Size([1, 6, 28, 28])\n",
"AvgPool2d output shape: \t torch.Size([1, 6, 14, 14])\n",
"Conv2d output shape: \t torch.Size([1, 16, 10, 10])\n",
"Sigmoid output shape: \t torch.Size([1, 16, 10, 10])\n",
"AvgPool2d output shape: \t torch.Size([1, 16, 5, 5])\n",
"Flatten output shape: \t torch.Size([1, 400])\n",
"Linear output shape: \t torch.Size([1, 120])\n",
"Sigmoid output shape: \t torch.Size([1, 120])\n",
"Linear output shape: \t torch.Size([1, 84])\n",
"Sigmoid output shape: \t torch.Size([1, 84])\n",
"Linear output shape: \t torch.Size([1, 10])\n"
]
}
],
"source": [
"X = torch.rand(size=(1, 1, 28, 28), dtype=torch.float32)\n",
"for layer in net:\n",
" X = layer(X)\n",
" print(layer.__class__.__name__,'output shape: \\t',X.shape)"
]
},
{
"cell_type": "markdown",
"id": "97b8c6d4-e9ff-4a47-94f9-9f12348683c3",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"LeNet在Fashion-MNIST数据集上的表现"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "f0f07725-b2d3-4461-92f3-e8465153bd96",
"metadata": {
"origin_pos": 9,
"tab": [
"pytorch"
]
},
"outputs": [],
"source": [
"batch_size = 256\n",
"train_iter, test_iter = d2l.load_data_fashion_mnist(batch_size=batch_size)"
]
},
{
"cell_type": "markdown",
"id": "4b457e3e-b2b0-4bab-9821-7ed7ce2e3f7f",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"对\n",
"`evaluate_accuracy`函数进行轻微的修改"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "43a68342-901c-4d8e-8066-c3f6b0f32a2a",
"metadata": {
"origin_pos": 13,
"tab": [
"pytorch"
]
},
"outputs": [],
"source": [
"def evaluate_accuracy_gpu(net, data_iter, device=None): \n",
" \"\"\"使用GPU计算模型在数据集上的精度\"\"\"\n",
" if isinstance(net, nn.Module):\n",
" net.eval() # 设置为评估模式\n",
" if not device:\n",
" device = next(iter(net.parameters())).device\n",
" metric = d2l.Accumulator(2) # 正确预测的数量,总预测的数量\n",
" with torch.no_grad():\n",
" for X, y in data_iter:\n",
" if isinstance(X, list): # BERT微调所需(之后介绍)\n",
" X = [x.to(device) for x in X]\n",
" else:\n",
" X = X.to(device)\n",
" y = y.to(device)\n",
" metric.add(d2l.accuracy(net(X), y), y.numel())\n",
" return metric[0] / metric[1]"
]
},
{
"cell_type": "markdown",
"id": "0fb6644e-bfe3-47da-acdc-e223e632801d",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"为了使用GPU,我们还需要一点小改动"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "c7b9b01a-3c00-4e6d-b991-06c081e442bf",
"metadata": {
"origin_pos": 16,
"tab": [
"pytorch"
]
},
"outputs": [],
"source": [
"def train_ch6(net, train_iter, test_iter, num_epochs, lr, device):\n",
" \"\"\"用GPU训练模型(在第六章定义)\"\"\"\n",
" def init_weights(m):\n",
" if type(m) == nn.Linear or type(m) == nn.Conv2d:\n",
" nn.init.xavier_uniform_(m.weight)\n",
" net.apply(init_weights)\n",
" print('training on', device)\n",
" net.to(device)\n",
" optimizer = torch.optim.SGD(net.parameters(), lr=lr)\n",
" loss = nn.CrossEntropyLoss()\n",
" animator = d2l.Animator(xlabel='epoch', xlim=[1, num_epochs],\n",
" legend=['train loss', 'train acc', 'test acc'])\n",
" timer, num_batches = d2l.Timer(), len(train_iter)\n",
" for epoch in range(num_epochs):\n",
" metric = d2l.Accumulator(3) # 训练损失之和,训练准确率之和,样本数\n",
" net.train()\n",
" for i, (X, y) in enumerate(train_iter):\n",
" timer.start()\n",
" optimizer.zero_grad()\n",
" X, y = X.to(device), y.to(device)\n",
" y_hat = net(X)\n",
" l = loss(y_hat, y)\n",
" l.backward()\n",
" optimizer.step()\n",
" with torch.no_grad():\n",
" metric.add(l * X.shape[0], d2l.accuracy(y_hat, y), X.shape[0])\n",
" timer.stop()\n",
" train_l = metric[0] / metric[2]\n",
" train_acc = metric[1] / metric[2]\n",
" if (i + 1) % (num_batches // 5) == 0 or i == num_batches - 1:\n",
" animator.add(epoch + (i + 1) / num_batches,\n",
" (train_l, train_acc, None))\n",
" test_acc = evaluate_accuracy_gpu(net, test_iter)\n",
" animator.add(epoch + 1, (None, None, test_acc))\n",
" print(f'loss {train_l:.3f}, train acc {train_acc:.3f}, '\n",
" f'test acc {test_acc:.3f}')\n",
" print(f'{metric[2] * num_epochs / timer.sum():.1f} examples/sec '\n",
" f'on {str(device)}')"
]
},
{
"cell_type": "markdown",
"id": "a6c9ffd8-fc3a-4480-bb2a-8ec164f7fe37",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"训练和评估LeNet-5模型"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "103901ca-60e4-4694-96fd-02f56736c134",
"metadata": {
"origin_pos": 19,
"tab": [
"pytorch"
],
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"loss 0.472, train acc 0.823, test acc 0.786\n",
"3560.3 examples/sec on cpu\n"
]
},
{
"data": {
"image/svg+xml": [
"<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
"<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"238.965625pt\" height=\"183.35625pt\" viewBox=\"0 0 238.965625 183.35625\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n",
" <metadata>\n",
" <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n",
" <cc:Work>\n",
" <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n",
" <dc:date>2023-02-28T15:39:17.744575</dc:date>\n",
" <dc:format>image/svg+xml</dc:format>\n",
" <dc:creator>\n",
" <cc:Agent>\n",
" <dc:title>Matplotlib v3.5.1, https://matplotlib.org/</dc:title>\n",
" </cc:Agent>\n",
" </dc:creator>\n",
" </cc:Work>\n",
" </rdf:RDF>\n",
" </metadata>\n",
" <defs>\n",
" <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n",
" </defs>\n",
" <g id=\"figure_1\">\n",
" <g id=\"patch_1\">\n",
" <path d=\"M 0 183.35625 \n",
"L 238.965625 183.35625 \n",
"L 238.965625 0 \n",
"L 0 0 \n",
"z\n",
"\" style=\"fill: #ffffff\"/>\n",
" </g>\n",
" <g id=\"axes_1\">\n",
" <g id=\"patch_2\">\n",
" <path d=\"M 30.103125 145.8 \n",
"L 225.403125 145.8 \n",
"L 225.403125 7.2 \n",
"L 30.103125 7.2 \n",
"z\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 51.803125 145.8 \n",
"L 51.803125 7.2 \n",
"\" clip-path=\"url(#p11c6494acf)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
" </g>\n",
" <g id=\"line2d_2\">\n",
" <defs>\n",
" <path id=\"m7a4df18761\" d=\"M 0 0 \n",
"L 0 3.5 \n",
"\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
" </defs>\n",
" <g>\n",
" <use xlink:href=\"#m7a4df18761\" x=\"51.803125\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
" </g>\n",
" </g>\n",
" <g id=\"text_1\">\n",
" <!-- 2 -->\n",
" <g transform=\"translate(48.621875 160.398438)scale(0.1 -0.1)\">\n",
" <defs>\n",
" <path id=\"DejaVuSans-32\" d=\"M 1228 531 \n",
"L 3431 531 \n",
"L 3431 0 \n",
"L 469 0 \n",
"L 469 531 \n",
"Q 828 903 1448 1529 \n",
"Q 2069 2156 2228 2338 \n",
"Q 2531 2678 2651 2914 \n",
"Q 2772 3150 2772 3378 \n",
"Q 2772 3750 2511 3984 \n",
"Q 2250 4219 1831 4219 \n",
"Q 1534 4219 1204 4116 \n",
"Q 875 4013 500 3803 \n",
"L 500 4441 \n",
"Q 881 4594 1212 4672 \n",
"Q 1544 4750 1819 4750 \n",
"Q 2544 4750 2975 4387 \n",
"Q 3406 4025 3406 3419 \n",
"Q 3406 3131 3298 2873 \n",
"Q 3191 2616 2906 2266 \n",
"Q 2828 2175 2409 1742 \n",
"Q 1991 1309 1228 531 \n",
"z\n",
"\" transform=\"scale(0.015625)\"/>\n",
" </defs>\n",
" <use xlink:href=\"#DejaVuSans-32\"/>\n",
" </g>\n",
" </g>\n",
" </g>\n",
" <g id=\"xtick_2\">\n",
" <g id=\"line2d_3\">\n",
" <path d=\"M 95.203125 145.8 \n",
"L 95.203125 7.2 \n",
"\" clip-path=\"url(#p11c6494acf)\" 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=\"#m7a4df18761\" x=\"95.203125\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
" </g>\n",
" </g>\n",
" <g id=\"text_2\">\n",
" <!-- 4 -->\n",
" <g transform=\"translate(92.021875 160.398438)scale(0.1 -0.1)\">\n",
" <defs>\n",
" <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \n",
"L 825 1625 \n",
"L 2419 1625 \n",
"L 2419 4116 \n",
"z\n",
"M 2253 4666 \n",
"L 3047 4666 \n",
"L 3047 1625 \n",
"L 3713 1625 \n",
"L 3713 1100 \n",
"L 3047 1100 \n",
"L 3047 0 \n",
"L 2419 0 \n",
"L 2419 1100 \n",
"L 313 1100 \n",
"L 313 1709 \n",
"L 2253 4666 \n",
"z\n",
"\" transform=\"scale(0.015625)\"/>\n",
" </defs>\n",
" <use xlink:href=\"#DejaVuSans-34\"/>\n",
" </g>\n",
" </g>\n",
" </g>\n",
" <g id=\"xtick_3\">\n",
" <g id=\"line2d_5\">\n",
" <path d=\"M 138.603125 145.8 \n",
"L 138.603125 7.2 \n",
"\" clip-path=\"url(#p11c6494acf)\" 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=\"#m7a4df18761\" x=\"138.603125\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
" </g>\n",
" </g>\n",
" <g id=\"text_3\">\n",
" <!-- 6 -->\n",
" <g transform=\"translate(135.421875 160.398438)scale(0.1 -0.1)\">\n",
" <defs>\n",
" <path id=\"DejaVuSans-36\" d=\"M 2113 2584 \n",
"Q 1688 2584 1439 2293 \n",
"Q 1191 2003 1191 1497 \n",
"Q 1191 994 1439 701 \n",
"Q 1688 409 2113 409 \n",
"Q 2538 409 2786 701 \n",
"Q 3034 994 3034 1497 \n",
"Q 3034 2003 2786 2293 \n",
"Q 2538 2584 2113 2584 \n",
"z\n",
"M 3366 4563 \n",
"L 3366 3988 \n",
"Q 3128 4100 2886 4159 \n",
"Q 2644 4219 2406 4219 \n",
"Q 1781 4219 1451 3797 \n",
"Q 1122 3375 1075 2522 \n",
"Q 1259 2794 1537 2939 \n",
"Q 1816 3084 2150 3084 \n",
"Q 2853 3084 3261 2657 \n",
"Q 3669 2231 3669 1497 \n",
"Q 3669 778 3244 343 \n",
"Q 2819 -91 2113 -91 \n",
"Q 1303 -91 875 529 \n",
"Q 447 1150 447 2328 \n",
"Q 447 3434 972 4092 \n",
"Q 1497 4750 2381 4750 \n",
"Q 2619 4750 2861 4703 \n",
"Q 3103 4656 3366 4563 \n",
"z\n",
"\" transform=\"scale(0.015625)\"/>\n",
" </defs>\n",
" <use xlink:href=\"#DejaVuSans-36\"/>\n",
" </g>\n",
" </g>\n",
" </g>\n",
" <g id=\"xtick_4\">\n",
" <g id=\"line2d_7\">\n",
" <path d=\"M 182.003125 145.8 \n",
"L 182.003125 7.2 \n",
"\" clip-path=\"url(#p11c6494acf)\" 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=\"#m7a4df18761\" x=\"182.003125\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
" </g>\n",
" </g>\n",
" <g id=\"text_4\">\n",
" <!-- 8 -->\n",
" <g transform=\"translate(178.821875 160.398438)scale(0.1 -0.1)\">\n",
" <defs>\n",
" <path id=\"DejaVuSans-38\" d=\"M 2034 2216 \n",
"Q 1584 2216 1326 1975 \n",
"Q 1069 1734 1069 1313 \n",
"Q 1069 891 1326 650 \n",
"Q 1584 409 2034 409 \n",
"Q 2484 409 2743 651 \n",
"Q 3003 894 3003 1313 \n",
"Q 3003 1734 2745 1975 \n",
"Q 2488 2216 2034 2216 \n",
"z\n",
"M 1403 2484 \n",
"Q 997 2584 770 2862 \n",
"Q 544 3141 544 3541 \n",
"Q 544 4100 942 4425 \n",
"Q 1341 4750 2034 4750 \n",
"Q 2731 4750 3128 4425 \n",
"Q 3525 4100 3525 3541 \n",
"Q 3525 3141 3298 2862 \n",
"Q 3072 2584 2669 2484 \n",
"Q 3125 2378 3379 2068 \n",
"Q 3634 1759 3634 1313 \n",
"Q 3634 634 3220 271 \n",
"Q 2806 -91 2034 -91 \n",
"Q 1263 -91 848 271 \n",
"Q 434 634 434 1313 \n",
"Q 434 1759 690 2068 \n",
"Q 947 2378 1403 2484 \n",
"z\n",
"M 1172 3481 \n",
"Q 1172 3119 1398 2916 \n",
"Q 1625 2713 2034 2713 \n",
"Q 2441 2713 2670 2916 \n",
"Q 2900 3119 2900 3481 \n",
"Q 2900 3844 2670 4047 \n",
"Q 2441 4250 2034 4250 \n",
"Q 1625 4250 1398 4047 \n",
"Q 1172 3844 1172 3481 \n",
"z\n",
"\" transform=\"scale(0.015625)\"/>\n",
" </defs>\n",
" <use xlink:href=\"#DejaVuSans-38\"/>\n",
" </g>\n",
" </g>\n",
" </g>\n",
" <g id=\"xtick_5\">\n",
" <g id=\"line2d_9\">\n",
" <path d=\"M 225.403125 145.8 \n",
"L 225.403125 7.2 \n",
"\" clip-path=\"url(#p11c6494acf)\" 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=\"#m7a4df18761\" x=\"225.403125\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
" </g>\n",
" </g>\n",
" <g id=\"text_5\">\n",
" <!-- 10 -->\n",
" <g transform=\"translate(219.040625 160.398438)scale(0.1 -0.1)\">\n",
" <defs>\n",
" <path id=\"DejaVuSans-31\" d=\"M 794 531 \n",
"L 1825 531 \n",
"L 1825 4091 \n",
"L 703 3866 \n",
"L 703 4441 \n",
"L 1819 4666 \n",
"L 2450 4666 \n",
"L 2450 531 \n",
"L 3481 531 \n",
"L 3481 0 \n",
"L 794 0 \n",
"L 794 531 \n",
"z\n",
"\" transform=\"scale(0.015625)\"/>\n",
" <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \n",
"Q 1547 4250 1301 3770 \n",
"Q 1056 3291 1056 2328 \n",
"Q 1056 1369 1301 889 \n",
"Q 1547 409 2034 409 \n",
"Q 2525 409 2770 889 \n",
"Q 3016 1369 3016 2328 \n",
"Q 3016 3291 2770 3770 \n",
"Q 2525 4250 2034 4250 \n",
"z\n",
"M 2034 4750 \n",
"Q 2819 4750 3233 4129 \n",
"Q 3647 3509 3647 2328 \n",
"Q 3647 1150 3233 529 \n",
"Q 2819 -91 2034 -91 \n",
"Q 1250 -91 836 529 \n",
"Q 422 1150 422 2328 \n",
"Q 422 3509 836 4129 \n",
"Q 1250 4750 2034 4750 \n",
"z\n",
"\" transform=\"scale(0.015625)\"/>\n",
" </defs>\n",
" <use xlink:href=\"#DejaVuSans-31\"/>\n",
" <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n",
" </g>\n",
" </g>\n",
" </g>\n",
" <g id=\"text_6\">\n",
" <!-- epoch -->\n",
" <g transform=\"translate(112.525 174.076563)scale(0.1 -0.1)\">\n",
" <defs>\n",
" <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \n",
"L 3597 1613 \n",
"L 953 1613 \n",
"Q 991 1019 1311 708 \n",
"Q 1631 397 2203 397 \n",
"Q 2534 397 2845 478 \n",
"Q 3156 559 3463 722 \n",
"L 3463 178 \n",
"Q 3153 47 2828 -22 \n",
"Q 2503 -91 2169 -91 \n",
"Q 1331 -91 842 396 \n",
"Q 353 884 353 1716 \n",
"Q 353 2575 817 3079 \n",
"Q 1281 3584 2069 3584 \n",
"Q 2775 3584 3186 3129 \n",
"Q 3597 2675 3597 1894 \n",
"z\n",
"M 3022 2063 \n",
"Q 3016 2534 2758 2815 \n",
"Q 2500 3097 2075 3097 \n",
"Q 1594 3097 1305 2825 \n",
"Q 1016 2553 972 2059 \n",
"L 3022 2063 \n",
"z\n",
"\" transform=\"scale(0.015625)\"/>\n",
" <path id=\"DejaVuSans-70\" d=\"M 1159 525 \n",
"L 1159 -1331 \n",
"L 581 -1331 \n",
"L 581 3500 \n",
"L 1159 3500 \n",
"L 1159 2969 \n",
"Q 1341 3281 1617 3432 \n",
"Q 1894 3584 2278 3584 \n",
"Q 2916 3584 3314 3078 \n",
"Q 3713 2572 3713 1747 \n",
"Q 3713 922 3314 415 \n",
"Q 2916 -91 2278 -91 \n",
"Q 1894 -91 1617 61 \n",
"Q 1341 213 1159 525 \n",
"z\n",
"M 3116 1747 \n",
"Q 3116 2381 2855 2742 \n",
"Q 2594 3103 2138 3103 \n",
"Q 1681 3103 1420 2742 \n",
"Q 1159 2381 1159 1747 \n",
"Q 1159 1113 1420 752 \n",
"Q 1681 391 2138 391 \n",
"Q 2594 391 2855 752 \n",
"Q 3116 1113 3116 1747 \n",
"z\n",
"\" transform=\"scale(0.015625)\"/>\n",
" <path id=\"DejaVuSans-6f\" d=\"M 1959 3097 \n",
"Q 1497 3097 1228 2736 \n",
"Q 959 2375 959 1747 \n",
"Q 959 1119 1226 758 \n",
"Q 1494 397 1959 397 \n",
"Q 2419 397 2687 759 \n",
"Q 2956 1122 2956 1747 \n",
"Q 2956 2369 2687 2733 \n",
"Q 2419 3097 1959 3097 \n",
"z\n",
"M 1959 3584 \n",
"Q 2709 3584 3137 3096 \n",
"Q 3566 2609 3566 1747 \n",
"Q 3566 888 3137 398 \n",
"Q 2709 -91 1959 -91 \n",
"Q 1206 -91 779 398 \n",
"Q 353 888 353 1747 \n",
"Q 353 2609 779 3096 \n",
"Q 1206 3584 1959 3584 \n",
"z\n",
"\" transform=\"scale(0.015625)\"/>\n",
" <path id=\"DejaVuSans-63\" d=\"M 3122 3366 \n",
"L 3122 2828 \n",
"Q 2878 2963 2633 3030 \n",
"Q 2388 3097 2138 3097 \n",
"Q 1578 3097 1268 2742 \n",
"Q 959 2388 959 1747 \n",
"Q 959 1106 1268 751 \n",
"Q 1578 397 2138 397 \n",
"Q 2388 397 2633 464 \n",
"Q 2878 531 3122 666 \n",
"L 3122 134 \n",
"Q 2881 22 2623 -34 \n",
"Q 2366 -91 2075 -91 \n",
"Q 1284 -91 818 406 \n",
"Q 353 903 353 1747 \n",
"Q 353 2603 823 3093 \n",
"Q 1294 3584 2113 3584 \n",
"Q 2378 3584 2631 3529 \n",
"Q 2884 3475 3122 3366 \n",
"z\n",
"\" transform=\"scale(0.015625)\"/>\n",
" <path id=\"DejaVuSans-68\" d=\"M 3513 2113 \n",
"L 3513 0 \n",
"L 2938 0 \n",
"L 2938 2094 \n",
"Q 2938 2591 2744 2837 \n",
"Q 2550 3084 2163 3084 \n",
"Q 1697 3084 1428 2787 \n",
"Q 1159 2491 1159 1978 \n",
"L 1159 0 \n",
"L 581 0 \n",
"L 581 4863 \n",
"L 1159 4863 \n",
"L 1159 2956 \n",
"Q 1366 3272 1645 3428 \n",
"Q 1925 3584 2291 3584 \n",
"Q 2894 3584 3203 3211 \n",
"Q 3513 2838 3513 2113 \n",
"z\n",
"\" transform=\"scale(0.015625)\"/>\n",
" </defs>\n",
" <use xlink:href=\"#DejaVuSans-65\"/>\n",
" <use xlink:href=\"#DejaVuSans-70\" x=\"61.523438\"/>\n",
" <use xlink:href=\"#DejaVuSans-6f\" x=\"125\"/>\n",
" <use xlink:href=\"#DejaVuSans-63\" x=\"186.181641\"/>\n",
" <use xlink:href=\"#DejaVuSans-68\" x=\"241.162109\"/>\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 144.92905 \n",
"L 225.403125 144.92905 \n",
"\" clip-path=\"url(#p11c6494acf)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
" </g>\n",
" <g id=\"line2d_12\">\n",
" <defs>\n",
" <path id=\"m05c2578c59\" d=\"M 0 0 \n",
"L -3.5 0 \n",
"\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
" </defs>\n",
" <g>\n",
" <use xlink:href=\"#m05c2578c59\" x=\"30.103125\" y=\"144.92905\" 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 148.728269)scale(0.1 -0.1)\">\n",
" <defs>\n",
" <path id=\"DejaVuSans-2e\" d=\"M 684 794 \n",
"L 1344 794 \n",
"L 1344 0 \n",
"L 684 0 \n",
"L 684 794 \n",
"z\n",
"\" transform=\"scale(0.015625)\"/>\n",
" </defs>\n",
" <use xlink:href=\"#DejaVuSans-30\"/>\n",
" <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n",
" <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n",
" </g>\n",
" </g>\n",
" </g>\n",
" <g id=\"ytick_2\">\n",
" <g id=\"line2d_13\">\n",
" <path d=\"M 30.103125 117.304722 \n",
"L 225.403125 117.304722 \n",
"\" clip-path=\"url(#p11c6494acf)\" 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=\"#m05c2578c59\" x=\"30.103125\" y=\"117.304722\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
" </g>\n",
" </g>\n",
" <g id=\"text_8\">\n",
" <!-- 0.5 -->\n",
" <g transform=\"translate(7.2 121.10394)scale(0.1 -0.1)\">\n",
" <defs>\n",
" <path id=\"DejaVuSans-35\" d=\"M 691 4666 \n",
"L 3169 4666 \n",
"L 3169 4134 \n",
"L 1269 4134 \n",
"L 1269 2991 \n",
"Q 1406 3038 1543 3061 \n",
"Q 1681 3084 1819 3084 \n",
"Q 2600 3084 3056 2656 \n",
"Q 3513 2228 3513 1497 \n",
"Q 3513 744 3044 326 \n",
"Q 2575 -91 1722 -91 \n",
"Q 1428 -91 1123 -41 \n",
"Q 819 9 494 109 \n",
"L 494 744 \n",
"Q 775 591 1075 516 \n",
"Q 1375 441 1709 441 \n",
"Q 2250 441 2565 725 \n",
"Q 2881 1009 2881 1497 \n",
"Q 2881 1984 2565 2268 \n",
"Q 2250 2553 1709 2553 \n",
"Q 1456 2553 1204 2497 \n",
"Q 953 2441 691 2322 \n",
"L 691 4666 \n",
"z\n",
"\" transform=\"scale(0.015625)\"/>\n",
" </defs>\n",
" <use xlink:href=\"#DejaVuSans-30\"/>\n",
" <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n",
" <use xlink:href=\"#DejaVuSans-35\" x=\"95.410156\"/>\n",
" </g>\n",
" </g>\n",
" </g>\n",
" <g id=\"ytick_3\">\n",
" <g id=\"line2d_15\">\n",
" <path d=\"M 30.103125 89.680394 \n",
"L 225.403125 89.680394 \n",
"\" clip-path=\"url(#p11c6494acf)\" 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=\"#m05c2578c59\" x=\"30.103125\" y=\"89.680394\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
" </g>\n",
" </g>\n",
" <g id=\"text_9\">\n",
" <!-- 1.0 -->\n",
" <g transform=\"translate(7.2 93.479612)scale(0.1 -0.1)\">\n",
" <use xlink:href=\"#DejaVuSans-31\"/>\n",
" <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n",
" <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n",
" </g>\n",
" </g>\n",
" </g>\n",
" <g id=\"ytick_4\">\n",
" <g id=\"line2d_17\">\n",
" <path d=\"M 30.103125 62.056065 \n",
"L 225.403125 62.056065 \n",
"\" clip-path=\"url(#p11c6494acf)\" 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=\"#m05c2578c59\" x=\"30.103125\" y=\"62.056065\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
" </g>\n",
" </g>\n",
" <g id=\"text_10\">\n",
" <!-- 1.5 -->\n",
" <g transform=\"translate(7.2 65.855284)scale(0.1 -0.1)\">\n",
" <use xlink:href=\"#DejaVuSans-31\"/>\n",
" <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n",
" <use xlink:href=\"#DejaVuSans-35\" x=\"95.410156\"/>\n",
" </g>\n",
" </g>\n",
" </g>\n",
" <g id=\"ytick_5\">\n",
" <g id=\"line2d_19\">\n",
" <path d=\"M 30.103125 34.431737 \n",
"L 225.403125 34.431737 \n",
"\" clip-path=\"url(#p11c6494acf)\" 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=\"#m05c2578c59\" x=\"30.103125\" y=\"34.431737\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
" </g>\n",
" </g>\n",
" <g id=\"text_11\">\n",
" <!-- 2.0 -->\n",
" <g transform=\"translate(7.2 38.230956)scale(0.1 -0.1)\">\n",
" <use xlink:href=\"#DejaVuSans-32\"/>\n",
" <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n",
" <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n",
" </g>\n",
" </g>\n",
" </g>\n",
" </g>\n",
" <g id=\"line2d_21\">\n",
" <path d=\"M 12.743125 13.5 \n",
"L 17.083125 15.353781 \n",
"L 21.423125 15.995517 \n",
"L 25.763125 16.374492 \n",
"L 30.103125 16.606067 \n",
"L 34.443125 17.599465 \n",
"L 38.783125 17.795762 \n",
"L 43.123125 20.003851 \n",
"L 47.463125 30.380947 \n",
"L 51.803125 40.203444 \n",
"L 56.143125 85.938867 \n",
"L 60.483125 88.258016 \n",
"L 64.823125 89.857148 \n",
"L 69.163125 90.981871 \n",
"L 73.503125 92.373457 \n",
"L 77.843125 99.001885 \n",
"L 82.183125 101.002988 \n",
"L 86.523125 102.360635 \n",
"L 90.863125 103.278956 \n",
"L 95.203125 103.773489 \n",
"L 99.543125 107.828465 \n",
"L 103.883125 108.007027 \n",
"L 108.223125 108.247005 \n",
"L 112.563125 108.678985 \n",
"L 116.903125 108.892108 \n",
"L 121.243125 109.860471 \n",
"L 125.583125 110.880218 \n",
"L 129.923125 111.274089 \n",
"L 134.263125 111.583757 \n",
"L 138.603125 111.743486 \n",
"L 142.943125 113.201064 \n",
"L 147.283125 113.708078 \n",
"L 151.623125 113.841268 \n",
"L 155.963125 113.88866 \n",
"L 160.303125 114.217182 \n",
"L 164.643125 116.237955 \n",
"L 168.983125 116.248697 \n",
"L 173.323125 115.969593 \n",
"L 177.663125 115.992826 \n",
"L 182.003125 116.162954 \n",
"L 186.343125 116.783973 \n",
"L 190.683125 116.867713 \n",
"L 195.023125 117.025351 \n",
"L 199.363125 117.240846 \n",
"L 203.703125 117.504063 \n",
"L 208.043125 118.255615 \n",
"L 212.383125 118.426405 \n",
"L 216.723125 118.613277 \n",
"L 221.063125 118.748246 \n",
"L 225.403125 118.836354 \n",
"\" clip-path=\"url(#p11c6494acf)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n",
" </g>\n",
" <g id=\"line2d_22\">\n",
" <path d=\"M 12.743125 139.285716 \n",
"L 17.083125 139.418878 \n",
"L 21.423125 139.5 \n",
"L 25.763125 139.455613 \n",
"L 30.103125 139.414313 \n",
"L 34.443125 139.198471 \n",
"L 38.783125 138.842606 \n",
"L 43.123125 137.609705 \n",
"L 47.463125 133.881155 \n",
"L 51.803125 130.289998 \n",
"L 56.143125 113.810354 \n",
"L 60.483125 112.816228 \n",
"L 64.823125 111.903223 \n",
"L 69.163125 111.388175 \n",
"L 73.503125 110.682249 \n",
"L 77.843125 107.413963 \n",
"L 82.183125 106.734375 \n",
"L 86.523125 106.224685 \n",
"L 90.863125 105.889482 \n",
"L 95.203125 105.696058 \n",
"L 99.543125 104.190513 \n",
"L 103.883125 103.997657 \n",
"L 108.223125 103.916535 \n",
"L 112.563125 103.828908 \n",
"L 116.903125 103.773405 \n",
"L 121.243125 103.331844 \n",
"L 125.583125 102.852 \n",
"L 129.923125 102.684399 \n",
"L 134.263125 102.535165 \n",
"L 138.603125 102.506369 \n",
"L 142.943125 101.94971 \n",
"L 147.283125 101.616803 \n",
"L 151.623125 101.663487 \n",
"L 155.963125 101.671905 \n",
"L 160.303125 101.523864 \n",
"L 164.643125 100.843083 \n",
"L 168.983125 100.776502 \n",
"L 173.323125 100.872165 \n",
"L 177.663125 100.814385 \n",
"L 182.003125 100.723679 \n",
"L 186.343125 100.457371 \n",
"L 190.683125 100.315025 \n",
"L 195.023125 100.293597 \n",
"L 199.363125 100.148572 \n",
"L 203.703125 100.057933 \n",
"L 208.043125 100.039517 \n",
"L 212.383125 99.674468 \n",
"L 216.723125 99.595642 \n",
"L 221.063125 99.494239 \n",
"L 225.403125 99.48703 \n",
"\" clip-path=\"url(#p11c6494acf)\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #bf00bf; stroke-width: 1.5\"/>\n",
" </g>\n",
" <g id=\"line2d_23\">\n",
" <path d=\"M 30.103125 139.404184 \n",
"L 51.803125 116.813009 \n",
"L 73.503125 108.575434 \n",
"L 95.203125 105.84615 \n",
"L 116.903125 103.846149 \n",
"L 138.603125 102.498082 \n",
"L 160.303125 101.636203 \n",
"L 182.003125 101.575429 \n",
"L 203.703125 101.835098 \n",
"L 225.403125 101.520181 \n",
"\" clip-path=\"url(#p11c6494acf)\" 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 145.8 \n",
"L 30.103125 7.2 \n",
"\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
" </g>\n",
" <g id=\"patch_4\">\n",
" <path d=\"M 225.403125 145.8 \n",
"L 225.403125 7.2 \n",
"\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
" </g>\n",
" <g id=\"patch_5\">\n",
" <path d=\"M 30.103125 145.8 \n",
"L 225.403125 145.8 \n",
"\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
" </g>\n",
" <g id=\"patch_6\">\n",
" <path d=\"M 30.103125 7.2 \n",
"L 225.403125 7.2 \n",
"\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
" </g>\n",
" <g id=\"legend_1\">\n",
" <g id=\"patch_7\">\n",
" <path d=\"M 140.634375 59.234375 \n",
"L 218.403125 59.234375 \n",
"Q 220.403125 59.234375 220.403125 57.234375 \n",
"L 220.403125 14.2 \n",
"Q 220.403125 12.2 218.403125 12.2 \n",
"L 140.634375 12.2 \n",
"Q 138.634375 12.2 138.634375 14.2 \n",
"L 138.634375 57.234375 \n",
"Q 138.634375 59.234375 140.634375 59.234375 \n",
"z\n",
"\" style=\"fill: #ffffff; opacity: 0.8; stroke: #cccccc; stroke-linejoin: miter\"/>\n",
" </g>\n",
" <g id=\"line2d_24\">\n",
" <path d=\"M 142.634375 20.298438 \n",
"L 152.634375 20.298438 \n",
"L 162.634375 20.298438 \n",
"\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n",
" </g>\n",
" <g id=\"text_12\">\n",
" <!-- train loss -->\n",
" <g transform=\"translate(170.634375 23.798438)scale(0.1 -0.1)\">\n",
" <defs>\n",
" <path id=\"DejaVuSans-74\" d=\"M 1172 4494 \n",
"L 1172 3500 \n",
"L 2356 3500 \n",
"L 2356 3053 \n",
"L 1172 3053 \n",
"L 1172 1153 \n",
"Q 1172 725 1289 603 \n",
"Q 1406 481 1766 481 \n",
"L 2356 481 \n",
"L 2356 0 \n",
"L 1766 0 \n",
"Q 1100 0 847 248 \n",
"Q 594 497 594 1153 \n",
"L 594 3053 \n",
"L 172 3053 \n",
"L 172 3500 \n",
"L 594 3500 \n",
"L 594 4494 \n",
"L 1172 4494 \n",
"z\n",
"\" transform=\"scale(0.015625)\"/>\n",
" <path id=\"DejaVuSans-72\" d=\"M 2631 2963 \n",
"Q 2534 3019 2420 3045 \n",
"Q 2306 3072 2169 3072 \n",
"Q 1681 3072 1420 2755 \n",
"Q 1159 2438 1159 1844 \n",
"L 1159 0 \n",
"L 581 0 \n",
"L 581 3500 \n",
"L 1159 3500 \n",
"L 1159 2956 \n",
"Q 1341 3275 1631 3429 \n",
"Q 1922 3584 2338 3584 \n",
"Q 2397 3584 2469 3576 \n",
"Q 2541 3569 2628 3553 \n",
"L 2631 2963 \n",
"z\n",
"\" transform=\"scale(0.015625)\"/>\n",
" <path id=\"DejaVuSans-61\" d=\"M 2194 1759 \n",
"Q 1497 1759 1228 1600 \n",
"Q 959 1441 959 1056 \n",
"Q 959 750 1161 570 \n",
"Q 1363 391 1709 391 \n",
"Q 2188 391 2477 730 \n",
"Q 2766 1069 2766 1631 \n",
"L 2766 1759 \n",
"L 2194 1759 \n",
"z\n",
"M 3341 1997 \n",
"L 3341 0 \n",
"L 2766 0 \n",
"L 2766 531 \n",
"Q 2569 213 2275 61 \n",
"Q 1981 -91 1556 -91 \n",
"Q 1019 -91 701 211 \n",
"Q 384 513 384 1019 \n",
"Q 384 1609 779 1909 \n",
"Q 1175 2209 1959 2209 \n",
"L 2766 2209 \n",
"L 2766 2266 \n",
"Q 2766 2663 2505 2880 \n",
"Q 2244 3097 1772 3097 \n",
"Q 1472 3097 1187 3025 \n",
"Q 903 2953 641 2809 \n",
"L 641 3341 \n",
"Q 956 3463 1253 3523 \n",
"Q 1550 3584 1831 3584 \n",
"Q 2591 3584 2966 3190 \n",
"Q 3341 2797 3341 1997 \n",
"z\n",
"\" transform=\"scale(0.015625)\"/>\n",
" <path id=\"DejaVuSans-69\" d=\"M 603 3500 \n",
"L 1178 3500 \n",
"L 1178 0 \n",
"L 603 0 \n",
"L 603 3500 \n",
"z\n",
"M 603 4863 \n",
"L 1178 4863 \n",
"L 1178 4134 \n",
"L 603 4134 \n",
"L 603 4863 \n",
"z\n",
"\" transform=\"scale(0.015625)\"/>\n",
" <path id=\"DejaVuSans-6e\" d=\"M 3513 2113 \n",
"L 3513 0 \n",
"L 2938 0 \n",
"L 2938 2094 \n",
"Q 2938 2591 2744 2837 \n",
"Q 2550 3084 2163 3084 \n",
"Q 1697 3084 1428 2787 \n",
"Q 1159 2491 1159 1978 \n",
"L 1159 0 \n",
"L 581 0 \n",
"L 581 3500 \n",
"L 1159 3500 \n",
"L 1159 2956 \n",
"Q 1366 3272 1645 3428 \n",
"Q 1925 3584 2291 3584 \n",
"Q 2894 3584 3203 3211 \n",
"Q 3513 2838 3513 2113 \n",
"z\n",
"\" transform=\"scale(0.015625)\"/>\n",
" <path id=\"DejaVuSans-20\" transform=\"scale(0.015625)\"/>\n",
" <path id=\"DejaVuSans-6c\" d=\"M 603 4863 \n",
"L 1178 4863 \n",
"L 1178 0 \n",
"L 603 0 \n",
"L 603 4863 \n",
"z\n",
"\" transform=\"scale(0.015625)\"/>\n",
" <path id=\"DejaVuSans-73\" d=\"M 2834 3397 \n",
"L 2834 2853 \n",
"Q 2591 2978 2328 3040 \n",
"Q 2066 3103 1784 3103 \n",
"Q 1356 3103 1142 2972 \n",
"Q 928 2841 928 2578 \n",
"Q 928 2378 1081 2264 \n",
"Q 1234 2150 1697 2047 \n",
"L 1894 2003 \n",
"Q 2506 1872 2764 1633 \n",
"Q 3022 1394 3022 966 \n",
"Q 3022 478 2636 193 \n",
"Q 2250 -91 1575 -91 \n",
"Q 1294 -91 989 -36 \n",
"Q 684 19 347 128 \n",
"L 347 722 \n",
"Q 666 556 975 473 \n",
"Q 1284 391 1588 391 \n",
"Q 1994 391 2212 530 \n",
"Q 2431 669 2431 922 \n",
"Q 2431 1156 2273 1281 \n",
"Q 2116 1406 1581 1522 \n",
"L 1381 1569 \n",
"Q 847 1681 609 1914 \n",
"Q 372 2147 372 2553 \n",
"Q 372 3047 722 3315 \n",
"Q 1072 3584 1716 3584 \n",
"Q 2034 3584 2315 3537 \n",
"Q 2597 3491 2834 3397 \n",
"z\n",
"\" transform=\"scale(0.015625)\"/>\n",
" </defs>\n",
" <use xlink:href=\"#DejaVuSans-74\"/>\n",
" <use xlink:href=\"#DejaVuSans-72\" x=\"39.208984\"/>\n",
" <use xlink:href=\"#DejaVuSans-61\" x=\"80.322266\"/>\n",
" <use xlink:href=\"#DejaVuSans-69\" x=\"141.601562\"/>\n",
" <use xlink:href=\"#DejaVuSans-6e\" x=\"169.384766\"/>\n",
" <use xlink:href=\"#DejaVuSans-20\" x=\"232.763672\"/>\n",
" <use xlink:href=\"#DejaVuSans-6c\" x=\"264.550781\"/>\n",
" <use xlink:href=\"#DejaVuSans-6f\" x=\"292.333984\"/>\n",
" <use xlink:href=\"#DejaVuSans-73\" x=\"353.515625\"/>\n",
" <use xlink:href=\"#DejaVuSans-73\" x=\"405.615234\"/>\n",
" </g>\n",
" </g>\n",
" <g id=\"line2d_25\">\n",
" <path d=\"M 142.634375 34.976563 \n",
"L 152.634375 34.976563 \n",
"L 162.634375 34.976563 \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",
" <!-- train acc -->\n",
" <g transform=\"translate(170.634375 38.476563)scale(0.1 -0.1)\">\n",
" <use xlink:href=\"#DejaVuSans-74\"/>\n",
" <use xlink:href=\"#DejaVuSans-72\" x=\"39.208984\"/>\n",
" <use xlink:href=\"#DejaVuSans-61\" x=\"80.322266\"/>\n",
" <use xlink:href=\"#DejaVuSans-69\" x=\"141.601562\"/>\n",
" <use xlink:href=\"#DejaVuSans-6e\" x=\"169.384766\"/>\n",
" <use xlink:href=\"#DejaVuSans-20\" x=\"232.763672\"/>\n",
" <use xlink:href=\"#DejaVuSans-61\" x=\"264.550781\"/>\n",
" <use xlink:href=\"#DejaVuSans-63\" x=\"325.830078\"/>\n",
" <use xlink:href=\"#DejaVuSans-63\" x=\"380.810547\"/>\n",
" </g>\n",
" </g>\n",
" <g id=\"line2d_26\">\n",
" <path d=\"M 142.634375 49.654688 \n",
"L 152.634375 49.654688 \n",
"L 162.634375 49.654688 \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",
" <!-- test acc -->\n",
" <g transform=\"translate(170.634375 53.154688)scale(0.1 -0.1)\">\n",
" <use xlink:href=\"#DejaVuSans-74\"/>\n",
" <use xlink:href=\"#DejaVuSans-65\" x=\"39.208984\"/>\n",
" <use xlink:href=\"#DejaVuSans-73\" x=\"100.732422\"/>\n",
" <use xlink:href=\"#DejaVuSans-74\" x=\"152.832031\"/>\n",
" <use xlink:href=\"#DejaVuSans-20\" x=\"192.041016\"/>\n",
" <use xlink:href=\"#DejaVuSans-61\" x=\"223.828125\"/>\n",
" <use xlink:href=\"#DejaVuSans-63\" x=\"285.107422\"/>\n",
" <use xlink:href=\"#DejaVuSans-63\" x=\"340.087891\"/>\n",
" </g>\n",
" </g>\n",
" </g>\n",
" </g>\n",
" </g>\n",
" <defs>\n",
" <clipPath id=\"p11c6494acf\">\n",
" <rect x=\"30.103125\" y=\"7.2\" width=\"195.3\" height=\"138.6\"/>\n",
" </clipPath>\n",
" </defs>\n",
"</svg>\n"
],
"text/plain": [
"<Figure size 350x250 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"lr, num_epochs = 0.9, 10\n",
"train_ch6(net, train_iter, test_iter, num_epochs, lr, d2l.try_gpu())"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.16"
}
},
"nbformat": 4,
"nbformat_minor": 5
}