Browse Source

Fix some errors; Improve README

pull/4/MERGE
bushuhui 4 years ago
parent
commit
4da59bbe7f
15 changed files with 403 additions and 384 deletions
  1. +1
    -1
      5_nn/3-softmax_ce.ipynb
  2. +114
    -133
      6_pytorch/0_basic/1-Tensor-and-Variable.ipynb
  3. +111
    -99
      6_pytorch/0_basic/2-autograd.ipynb
  4. +21
    -17
      6_pytorch/0_basic/3-dynamic-graph.ipynb
  5. +84
    -84
      6_pytorch/1_NN/1-linear-regression-gradient-descend.ipynb
  6. +1
    -1
      6_pytorch/1_NN/4-deep-nn.ipynb
  7. +1
    -1
      6_pytorch/1_NN/5-param_initialize.ipynb
  8. +1
    -1
      6_pytorch/1_NN/6-nn_summary.ipynb
  9. +43
    -35
      6_pytorch/2_CNN/1-basic_conv.ipynb
  10. +6
    -3
      6_pytorch/2_CNN/2-batch-normalization.ipynb
  11. +15
    -5
      6_pytorch/2_CNN/4-data-augumentation.ipynb
  12. +1
    -1
      6_pytorch/2_CNN/8-resnet.ipynb
  13. BIN
      6_pytorch/2_CNN/CNN_Introduction.pptx
  14. BIN
      6_pytorch/2_CNN/images/data_normalize.png
  15. +4
    -3
      README.md

+ 1
- 1
5_nn/3-softmax_ce.ipynb View File

@@ -83,7 +83,7 @@
"\n", "\n",
"其中$W_{ij}$是第$i$个神经元的第$j$个权重,$b$是偏置。$z_i$表示该网络的第$i$个输出。\n", "其中$W_{ij}$是第$i$个神经元的第$j$个权重,$b$是偏置。$z_i$表示该网络的第$i$个输出。\n",
"\n", "\n",
"给这个输出加上一个softmax函数,那就变成了这样:\n",
"给这个输出加上一个softmax函数,那就变成了这样(FIXME: need sigmod):\n",
"\n", "\n",
"$$\n", "$$\n",
"a_i = \\frac{e^{z_i}}{\\sum_k e^{z_k}}\n", "a_i = \\frac{e^{z_i}}{\\sum_k e^{z_k}}\n",


+ 114
- 133
6_pytorch/0_basic/1-Tensor-and-Variable.ipynb View File

@@ -26,7 +26,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5,
"execution_count": 1,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -36,7 +36,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6,
"execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -53,7 +53,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7,
"execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -84,7 +84,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8,
"execution_count": 5,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -120,7 +120,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -130,7 +130,7 @@
"\n", "\n",
"# 第二种方式更简单,推荐使用\n", "# 第二种方式更简单,推荐使用\n",
"gpu_tensor = torch.randn(10, 20).cuda(0) # 将 tensor 放到第一个 GPU 上\n", "gpu_tensor = torch.randn(10, 20).cuda(0) # 将 tensor 放到第一个 GPU 上\n",
"gpu_tensor = torch.randn(10, 20).cuda(1) # 将 tensor 放到第二个 GPU 上"
"gpu_tensor = torch.randn(10, 20).cuda(0) # 将 tensor 放到第二个 GPU 上"
] ]
}, },
{ {
@@ -151,10 +151,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"execution_count": 9,
"metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"cpu_tensor = gpu_tensor.cpu()" "cpu_tensor = gpu_tensor.cpu()"
@@ -169,7 +167,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5,
"execution_count": 10,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -189,25 +187,27 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6,
"execution_count": 12,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"torch.FloatTensor\n"
"torch.FloatTensor\n",
"torch.cuda.FloatTensor\n"
] ]
} }
], ],
"source": [ "source": [
"# 得到 tensor 的数据类型\n", "# 得到 tensor 的数据类型\n",
"print(pytorch_tensor1.type())"
"print(pytorch_tensor1.type())\n",
"print(gpu_tensor.type())"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7,
"execution_count": 13,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -225,7 +225,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8,
"execution_count": 14,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -290,29 +290,27 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9,
"execution_count": 16,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"\n",
" 1 1\n",
" 1 1\n",
"[torch.FloatTensor of size 2x2]\n",
"\n"
"tensor([[1., 1.],\n",
" [1., 1.],\n",
" [1., 1.]])\n"
] ]
} }
], ],
"source": [ "source": [
"x = torch.ones(2, 2)\n",
"x = torch.ones(3, 2)\n",
"print(x) # 这是一个float tensor" "print(x) # 这是一个float tensor"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10,
"execution_count": 17,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -329,18 +327,16 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11,
"execution_count": 18,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"\n",
" 1 1\n",
" 1 1\n",
"[torch.LongTensor of size 2x2]\n",
"\n"
"tensor([[1, 1],\n",
" [1, 1],\n",
" [1, 1]])\n"
] ]
} }
], ],
@@ -353,18 +349,16 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12,
"execution_count": 19,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"\n",
" 1 1\n",
" 1 1\n",
"[torch.FloatTensor of size 2x2]\n",
"\n"
"tensor([[1., 1.],\n",
" [1., 1.],\n",
" [1., 1.]])\n"
] ]
} }
], ],
@@ -377,20 +371,17 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 13,
"execution_count": 20,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"\n",
"-0.8203 -0.0328 1.8283\n",
"-0.1734 -0.1873 0.9818\n",
"-1.8368 -2.2450 -0.4410\n",
"-0.8005 -2.1132 0.7140\n",
"[torch.FloatTensor of size 4x3]\n",
"\n"
"tensor([[-1.8509, 0.5228, -1.3782],\n",
" [ 0.9726, 1.7519, -0.3425],\n",
" [-0.0131, 2.1198, -1.1388],\n",
" [ 0.2897, 1.2477, -0.2862]])\n"
] ]
} }
], ],
@@ -401,10 +392,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": true
},
"execution_count": 21,
"metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"# 沿着行取最大值\n", "# 沿着行取最大值\n",
@@ -413,21 +402,16 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 15,
"execution_count": 22,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"\n",
" 1.8283\n",
" 0.9818\n",
"-0.4410\n",
" 0.7140\n",
"[torch.FloatTensor of size 4]"
"tensor([0.5228, 1.7519, 2.1198, 1.2477])"
] ]
}, },
"execution_count": 15,
"execution_count": 22,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -439,21 +423,16 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 16,
"execution_count": 23,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"\n",
" 2\n",
" 2\n",
" 2\n",
" 2\n",
"[torch.LongTensor of size 4]"
"tensor([1, 1, 1, 1])"
] ]
}, },
"execution_count": 16,
"execution_count": 23,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -465,20 +444,14 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 17,
"execution_count": 24,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"\n",
" 0.9751\n",
" 0.6212\n",
"-4.5228\n",
"-2.1997\n",
"[torch.FloatTensor of size 4]\n",
"\n"
"tensor([-2.7063, 2.3820, 0.9679, 1.2512])\n"
] ]
} }
], ],
@@ -490,15 +463,19 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 18,
"execution_count": 28,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"torch.Size([4, 3])\n",
"torch.Size([1, 4, 3])\n"
"torch.Size([1, 1, 1, 4, 3])\n",
"torch.Size([1, 1, 1, 1, 4, 3])\n",
"tensor([[[[[[-1.8509, 0.5228, -1.3782],\n",
" [ 0.9726, 1.7519, -0.3425],\n",
" [-0.0131, 2.1198, -1.1388],\n",
" [ 0.2897, 1.2477, -0.2862]]]]]])\n"
] ]
} }
], ],
@@ -506,7 +483,8 @@
"# 增加维度或者减少维度\n", "# 增加维度或者减少维度\n",
"print(x.shape)\n", "print(x.shape)\n",
"x = x.unsqueeze(0) # 在第一维增加\n", "x = x.unsqueeze(0) # 在第一维增加\n",
"print(x.shape)"
"print(x.shape)\n",
"print(x)"
] ]
}, },
{ {
@@ -529,25 +507,30 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 20,
"execution_count": 43,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"torch.Size([1, 4, 3])\n"
"torch.Size([4, 3])\n",
"tensor([[-1.8509, 0.5228, -1.3782],\n",
" [ 0.9726, 1.7519, -0.3425],\n",
" [-0.0131, 2.1198, -1.1388],\n",
" [ 0.2897, 1.2477, -0.2862]])\n"
] ]
} }
], ],
"source": [ "source": [
"x = x.squeeze(0) # 减少第一维\n", "x = x.squeeze(0) # 减少第一维\n",
"print(x.shape)"
"print(x.shape)\n",
"print(x)"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 21,
"execution_count": 44,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -565,7 +548,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 22,
"execution_count": 46,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -592,7 +575,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 23,
"execution_count": 47,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -619,10 +602,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 24,
"metadata": {
"collapsed": true
},
"execution_count": 48,
"metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"x = torch.randn(3, 4)\n", "x = torch.randn(3, 4)\n",
@@ -642,7 +623,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 25,
"execution_count": 49,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -670,11 +651,22 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"execution_count": 50,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"tensor([[1., 1., 1.],\n",
" [1., 1., 1.],\n",
" [1., 1., 1.]])\n",
"tensor([[2., 2., 2.],\n",
" [2., 2., 2.],\n",
" [2., 2., 2.]])\n"
]
}
],
"source": [ "source": [
"x = torch.ones(3, 3)\n", "x = torch.ones(3, 3)\n",
"y = torch.ones(3, 3)\n", "y = torch.ones(3, 3)\n",
@@ -745,7 +737,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4,
"execution_count": 51,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -755,7 +747,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 28,
"execution_count": 52,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -769,10 +761,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 29,
"metadata": {
"collapsed": true
},
"execution_count": 53,
"metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"z = torch.sum(x + y)" "z = torch.sum(x + y)"
@@ -780,18 +770,15 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 30,
"execution_count": 54,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"\n",
"-2.1379\n",
"[torch.FloatTensor of size 1]\n",
"\n",
"<SumBackward0 object at 0x10da636a0>\n"
"tensor(-6.3913)\n",
"<SumBackward0 object at 0x7f8a18db6e10>\n"
] ]
} }
], ],
@@ -809,39 +796,33 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 31,
"execution_count": 55,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"Variable containing:\n",
" 1 1 1 1 1\n",
" 1 1 1 1 1\n",
" 1 1 1 1 1\n",
" 1 1 1 1 1\n",
" 1 1 1 1 1\n",
" 1 1 1 1 1\n",
" 1 1 1 1 1\n",
" 1 1 1 1 1\n",
" 1 1 1 1 1\n",
" 1 1 1 1 1\n",
"[torch.FloatTensor of size 10x5]\n",
"\n",
"Variable containing:\n",
" 1 1 1 1 1\n",
" 1 1 1 1 1\n",
" 1 1 1 1 1\n",
" 1 1 1 1 1\n",
" 1 1 1 1 1\n",
" 1 1 1 1 1\n",
" 1 1 1 1 1\n",
" 1 1 1 1 1\n",
" 1 1 1 1 1\n",
" 1 1 1 1 1\n",
"[torch.FloatTensor of size 10x5]\n",
"\n"
"tensor([[1., 1., 1., 1., 1.],\n",
" [1., 1., 1., 1., 1.],\n",
" [1., 1., 1., 1., 1.],\n",
" [1., 1., 1., 1., 1.],\n",
" [1., 1., 1., 1., 1.],\n",
" [1., 1., 1., 1., 1.],\n",
" [1., 1., 1., 1., 1.],\n",
" [1., 1., 1., 1., 1.],\n",
" [1., 1., 1., 1., 1.],\n",
" [1., 1., 1., 1., 1.]])\n",
"tensor([[1., 1., 1., 1., 1.],\n",
" [1., 1., 1., 1., 1.],\n",
" [1., 1., 1., 1., 1.],\n",
" [1., 1., 1., 1., 1.],\n",
" [1., 1., 1., 1., 1.],\n",
" [1., 1., 1., 1., 1.],\n",
" [1., 1., 1., 1., 1.],\n",
" [1., 1., 1., 1., 1.],\n",
" [1., 1., 1., 1., 1.],\n",
" [1., 1., 1., 1., 1.]])\n"
] ]
} }
], ],
@@ -882,7 +863,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1,
"execution_count": 56,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -911,7 +892,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6,
"execution_count": 57,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {


+ 111
- 99
6_pytorch/0_basic/2-autograd.ipynb View File

@@ -28,7 +28,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -66,7 +66,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -92,47 +92,59 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8,
"execution_count": 9,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"tensor([[-1.5318, 1.5200, -2.1316, -1.3238, 1.0080, -1.0832, -0.2814, -1.0486,\n",
" 1.0807, -2.2865, 0.6545, -0.3595, 0.4229, -0.9194, 0.1690, -0.3241,\n",
" 1.8970, -0.8979, -0.7827, 0.3879],\n",
" [ 0.1404, -0.8016, 0.1156, -0.8397, -1.8886, 1.1072, -1.0186, 0.2249,\n",
" 0.5631, 0.4391, 0.7887, -2.3255, -0.4185, 0.6559, 0.7622, 1.6883,\n",
" -1.4147, 0.2579, -0.6177, 0.2172],\n",
" [-0.4866, -0.0322, -1.2484, 1.1913, -0.6569, 0.0810, 0.2491, -0.1258,\n",
" 2.5903, -0.8370, -0.0554, 1.2174, 0.4059, -1.0759, 0.6649, 0.1642,\n",
" -0.3512, -0.7695, 1.1469, -0.3409],\n",
" [ 1.8789, -1.6553, -0.7401, -0.3198, -0.1010, -0.5512, -0.4792, -0.2891,\n",
" -0.2655, -0.8132, 0.7210, 1.0885, -0.9557, -0.4472, -1.5340, 0.8093,\n",
" 0.9349, 0.8352, -0.0774, -0.1728],\n",
" [-0.3424, 0.1938, -2.4253, -0.0229, 0.3132, -0.7731, 0.8481, -1.3002,\n",
" -0.1595, -0.0364, -1.5733, 0.8882, 0.1909, -0.1404, -1.5673, -1.1809,\n",
" -0.7169, 0.7074, 0.3337, -1.0738],\n",
" [-0.0501, 1.6210, 0.6854, 0.2216, 0.3034, -1.2762, -0.6216, 1.4884,\n",
" 0.6078, 2.1512, -0.7141, 0.4110, -0.8187, 0.9474, -0.5978, -0.2679,\n",
" 1.5315, -2.1550, 2.0969, -1.7669],\n",
" [ 1.4505, -0.9497, 2.0269, -1.6402, -0.0047, -0.2716, -0.2727, 0.6795,\n",
" -0.7367, -0.3248, -0.5312, 0.0887, -1.4303, -0.8390, 1.5324, 0.3761,\n",
" -0.4658, -0.2044, 0.3050, -0.2756],\n",
" [ 0.3265, -0.2513, 1.1441, 0.3805, -1.3629, -1.3120, -1.8571, 0.1180,\n",
" 0.7466, -0.2654, -0.2154, 1.0603, -0.4113, -2.5965, 1.0736, 1.1610,\n",
" 0.8165, 1.5916, 1.5556, 0.3078],\n",
" [-0.4417, 0.1656, -2.1743, -0.1148, -1.2795, 1.0212, -0.7035, -0.8234,\n",
" 0.3010, -1.0891, -1.0676, 0.8385, -0.2886, -1.1881, 0.5097, -0.5097,\n",
" -1.7893, 0.0494, -0.0162, 1.5170],\n",
" [-0.6435, -1.8376, 1.0022, -0.0397, 0.7187, -0.0661, -0.8528, 1.3248,\n",
" -0.2566, -2.2886, 0.8728, -0.7152, 1.6180, 0.8416, 0.2788, 0.5515,\n",
" -0.1266, -1.0025, 0.1767, -0.4987]], requires_grad=True)\n"
"tensor([[ 5.7436e-01, -8.5241e-01, 2.2845e+00, 3.6574e-01, 1.4336e+00,\n",
" 6.2769e-01, -2.4378e-01, 2.3407e+00, 3.8966e-01, 1.1835e+00,\n",
" -6.4391e-01, 9.1353e-01, -5.8734e-01, -1.9392e+00, 9.3507e-01,\n",
" 8.8518e-02, 7.2412e-01, -1.0687e+00, -6.7646e-01, 1.2672e+00],\n",
" [ 7.2998e-01, 2.0229e+00, -5.0831e-01, -6.3940e-01, -8.7033e-01,\n",
" 2.7687e-01, 6.3498e-01, -1.8736e-03, -8.4395e-01, 1.4696e+00,\n",
" -1.7850e+00, -4.5297e-01, 9.2144e-01, 8.5070e-02, -5.8926e-01,\n",
" 1.2085e+00, -9.7894e-01, -3.4309e-01, -2.4711e-02, -6.4475e-01],\n",
" [-2.8774e-01, 1.2039e+00, -5.2320e-01, 1.3787e-01, 3.9971e-02,\n",
" -5.6454e-01, -1.5835e+00, -2.0742e-01, -1.4274e+00, -3.7860e-01,\n",
" 6.2642e-01, 1.6408e+00, -1.1916e-01, 1.4388e-01, -9.5261e-01,\n",
" 4.0784e-01, 8.1715e-01, 3.9228e-01, 4.1611e-01, -3.3709e-01],\n",
" [ 3.3040e-01, 1.7915e-01, -5.7069e-02, 1.1144e+00, -1.0322e+00,\n",
" 9.9129e-01, 1.1692e+00, 7.9638e-01, -1.0943e-01, 8.2714e-01,\n",
" -1.5700e-01, -5.6686e-01, -1.9550e-01, -1.2263e+00, 1.7836e+00,\n",
" 9.1989e-01, -6.4577e-01, 9.5402e-01, -8.6525e-01, 3.9199e-01],\n",
" [-8.8085e-01, -6.3551e-03, 1.6959e+00, -7.5292e-02, -8.8929e-02,\n",
" 1.0209e+00, 8.9355e-01, -1.2029e+00, 1.9429e+00, -2.7024e-01,\n",
" -9.1289e-01, -1.3788e+00, -6.2695e-01, -6.5776e-01, 3.3640e-01,\n",
" -1.0473e-01, 9.9417e-01, 1.0128e+00, 2.4199e+00, 2.8859e-01],\n",
" [ 8.0469e-02, -1.6585e-01, -4.9862e-01, -5.5413e-01, -4.9307e-01,\n",
" -7.3808e-01, 1.3946e-02, 5.6282e-01, 9.1096e-01, -1.9281e-01,\n",
" -3.8546e-01, -1.4070e+00, 7.3520e-01, 1.7412e+00, 1.0770e+00,\n",
" 1.4837e+00, -7.4241e-01, -4.0977e-01, 1.1057e+00, -7.0222e-01],\n",
" [-2.3147e-01, -3.7781e-01, 1.0774e+00, -7.9918e-01, 1.8275e+00,\n",
" 7.6937e-01, -2.7600e-01, 1.0389e+00, 1.4457e+00, -1.2898e+00,\n",
" 1.2761e-03, 5.5406e-01, 1.8231e+00, -2.3874e-01, 1.2145e+00,\n",
" -2.1051e+00, -6.6464e-01, -8.5335e-01, -2.6258e-01, 8.0080e-01],\n",
" [ 4.2173e-01, 1.7040e-01, -3.0126e-01, -5.2095e-01, 5.5845e-01,\n",
" 5.9780e-01, -6.8320e-01, -5.2203e-01, 4.9485e-01, -8.2392e-01,\n",
" -1.7584e-01, -1.3862e+00, 1.3604e+00, -7.5567e-01, 3.1400e-01,\n",
" 1.8617e+00, -1.1887e+00, -3.1732e-01, -1.5062e-01, -1.7251e-01],\n",
" [ 1.0924e+00, 1.0899e+00, 5.7135e-01, -2.7047e-01, 1.1123e+00,\n",
" 9.3634e-01, -1.4739e+00, 5.3640e-01, -8.2090e-02, 3.3112e-02,\n",
" 6.6032e-01, 1.1448e+00, -4.2457e-01, 1.2898e+00, 3.9002e-01,\n",
" 2.7646e-01, 9.6717e-03, -1.7425e-01, -1.9732e-01, 9.7876e-01],\n",
" [ 4.4554e-01, 5.3807e-01, -2.2031e-02, 1.3198e+00, -1.1642e+00,\n",
" -6.6617e-01, -2.6982e-01, -1.0219e+00, 5.8154e-01, 1.7617e+00,\n",
" 3.3077e-01, 1.5238e+00, -5.8909e-01, 1.1373e+00, 1.0998e+00,\n",
" -1.8168e+00, -5.0699e-01, 4.0043e-01, -2.3226e+00, 7.2522e-02]],\n",
" requires_grad=True)\n"
] ]
} }
], ],
"source": [ "source": [
"# FIXME: the demo need improve\n",
"x = Variable(torch.randn(10, 20), requires_grad=True)\n", "x = Variable(torch.randn(10, 20), requires_grad=True)\n",
"y = Variable(torch.randn(10, 5), requires_grad=True)\n", "y = Variable(torch.randn(10, 5), requires_grad=True)\n",
"w = Variable(torch.randn(20, 5), requires_grad=True)\n", "w = Variable(torch.randn(20, 5), requires_grad=True)\n",
@@ -150,43 +162,43 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9,
"execution_count": 6,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"tensor([[-0.0198, -0.0066, -0.0288, 0.0080, 0.0079, -0.0569, -0.0489, 0.0505,\n",
" 0.0132, -0.0072, -0.0024, 0.0400, 0.0691, -0.0273, 0.0124, 0.0104,\n",
" 0.0098, -0.0598, 0.0365, 0.0177],\n",
" [-0.0198, -0.0066, -0.0288, 0.0080, 0.0079, -0.0569, -0.0489, 0.0505,\n",
" 0.0132, -0.0072, -0.0024, 0.0400, 0.0691, -0.0273, 0.0124, 0.0104,\n",
" 0.0098, -0.0598, 0.0365, 0.0177],\n",
" [-0.0198, -0.0066, -0.0288, 0.0080, 0.0079, -0.0569, -0.0489, 0.0505,\n",
" 0.0132, -0.0072, -0.0024, 0.0400, 0.0691, -0.0273, 0.0124, 0.0104,\n",
" 0.0098, -0.0598, 0.0365, 0.0177],\n",
" [-0.0198, -0.0066, -0.0288, 0.0080, 0.0079, -0.0569, -0.0489, 0.0505,\n",
" 0.0132, -0.0072, -0.0024, 0.0400, 0.0691, -0.0273, 0.0124, 0.0104,\n",
" 0.0098, -0.0598, 0.0365, 0.0177],\n",
" [-0.0198, -0.0066, -0.0288, 0.0080, 0.0079, -0.0569, -0.0489, 0.0505,\n",
" 0.0132, -0.0072, -0.0024, 0.0400, 0.0691, -0.0273, 0.0124, 0.0104,\n",
" 0.0098, -0.0598, 0.0365, 0.0177],\n",
" [-0.0198, -0.0066, -0.0288, 0.0080, 0.0079, -0.0569, -0.0489, 0.0505,\n",
" 0.0132, -0.0072, -0.0024, 0.0400, 0.0691, -0.0273, 0.0124, 0.0104,\n",
" 0.0098, -0.0598, 0.0365, 0.0177],\n",
" [-0.0198, -0.0066, -0.0288, 0.0080, 0.0079, -0.0569, -0.0489, 0.0505,\n",
" 0.0132, -0.0072, -0.0024, 0.0400, 0.0691, -0.0273, 0.0124, 0.0104,\n",
" 0.0098, -0.0598, 0.0365, 0.0177],\n",
" [-0.0198, -0.0066, -0.0288, 0.0080, 0.0079, -0.0569, -0.0489, 0.0505,\n",
" 0.0132, -0.0072, -0.0024, 0.0400, 0.0691, -0.0273, 0.0124, 0.0104,\n",
" 0.0098, -0.0598, 0.0365, 0.0177],\n",
" [-0.0198, -0.0066, -0.0288, 0.0080, 0.0079, -0.0569, -0.0489, 0.0505,\n",
" 0.0132, -0.0072, -0.0024, 0.0400, 0.0691, -0.0273, 0.0124, 0.0104,\n",
" 0.0098, -0.0598, 0.0365, 0.0177],\n",
" [-0.0198, -0.0066, -0.0288, 0.0080, 0.0079, -0.0569, -0.0489, 0.0505,\n",
" 0.0132, -0.0072, -0.0024, 0.0400, 0.0691, -0.0273, 0.0124, 0.0104,\n",
" 0.0098, -0.0598, 0.0365, 0.0177]])\n"
"tensor([[ 0.0034, -0.0301, -0.0040, -0.0488, 0.0187, -0.0139, -0.0374, 0.0102,\n",
" 0.0337, -0.0249, -0.0777, -0.0868, 0.0132, 0.0042, -0.0627, -0.0448,\n",
" 0.0221, -0.0324, -0.0601, 0.0048],\n",
" [ 0.0034, -0.0301, -0.0040, -0.0488, 0.0187, -0.0139, -0.0374, 0.0102,\n",
" 0.0337, -0.0249, -0.0777, -0.0868, 0.0132, 0.0042, -0.0627, -0.0448,\n",
" 0.0221, -0.0324, -0.0601, 0.0048],\n",
" [ 0.0034, -0.0301, -0.0040, -0.0488, 0.0187, -0.0139, -0.0374, 0.0102,\n",
" 0.0337, -0.0249, -0.0777, -0.0868, 0.0132, 0.0042, -0.0627, -0.0448,\n",
" 0.0221, -0.0324, -0.0601, 0.0048],\n",
" [ 0.0034, -0.0301, -0.0040, -0.0488, 0.0187, -0.0139, -0.0374, 0.0102,\n",
" 0.0337, -0.0249, -0.0777, -0.0868, 0.0132, 0.0042, -0.0627, -0.0448,\n",
" 0.0221, -0.0324, -0.0601, 0.0048],\n",
" [ 0.0034, -0.0301, -0.0040, -0.0488, 0.0187, -0.0139, -0.0374, 0.0102,\n",
" 0.0337, -0.0249, -0.0777, -0.0868, 0.0132, 0.0042, -0.0627, -0.0448,\n",
" 0.0221, -0.0324, -0.0601, 0.0048],\n",
" [ 0.0034, -0.0301, -0.0040, -0.0488, 0.0187, -0.0139, -0.0374, 0.0102,\n",
" 0.0337, -0.0249, -0.0777, -0.0868, 0.0132, 0.0042, -0.0627, -0.0448,\n",
" 0.0221, -0.0324, -0.0601, 0.0048],\n",
" [ 0.0034, -0.0301, -0.0040, -0.0488, 0.0187, -0.0139, -0.0374, 0.0102,\n",
" 0.0337, -0.0249, -0.0777, -0.0868, 0.0132, 0.0042, -0.0627, -0.0448,\n",
" 0.0221, -0.0324, -0.0601, 0.0048],\n",
" [ 0.0034, -0.0301, -0.0040, -0.0488, 0.0187, -0.0139, -0.0374, 0.0102,\n",
" 0.0337, -0.0249, -0.0777, -0.0868, 0.0132, 0.0042, -0.0627, -0.0448,\n",
" 0.0221, -0.0324, -0.0601, 0.0048],\n",
" [ 0.0034, -0.0301, -0.0040, -0.0488, 0.0187, -0.0139, -0.0374, 0.0102,\n",
" 0.0337, -0.0249, -0.0777, -0.0868, 0.0132, 0.0042, -0.0627, -0.0448,\n",
" 0.0221, -0.0324, -0.0601, 0.0048],\n",
" [ 0.0034, -0.0301, -0.0040, -0.0488, 0.0187, -0.0139, -0.0374, 0.0102,\n",
" 0.0337, -0.0249, -0.0777, -0.0868, 0.0132, 0.0042, -0.0627, -0.0448,\n",
" 0.0221, -0.0324, -0.0601, 0.0048]])\n"
] ]
} }
], ],
@@ -197,7 +209,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10,
"execution_count": 7,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -224,33 +236,33 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11,
"execution_count": 8,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"tensor([[-0.0060, -0.0060, -0.0060, -0.0060, -0.0060],\n",
" [ 0.0405, 0.0405, 0.0405, 0.0405, 0.0405],\n",
" [ 0.0749, 0.0749, 0.0749, 0.0749, 0.0749],\n",
" [ 0.0502, 0.0502, 0.0502, 0.0502, 0.0502],\n",
" [ 0.0590, 0.0590, 0.0590, 0.0590, 0.0590],\n",
" [ 0.0625, 0.0625, 0.0625, 0.0625, 0.0625],\n",
" [ 0.0998, 0.0998, 0.0998, 0.0998, 0.0998],\n",
" [-0.0050, -0.0050, -0.0050, -0.0050, -0.0050],\n",
" [-0.0894, -0.0894, -0.0894, -0.0894, -0.0894],\n",
" [ 0.1070, 0.1070, 0.1070, 0.1070, 0.1070],\n",
" [ 0.0224, 0.0224, 0.0224, 0.0224, 0.0224],\n",
" [-0.0438, -0.0438, -0.0438, -0.0438, -0.0438],\n",
" [ 0.0337, 0.0337, 0.0337, 0.0337, 0.0337],\n",
" [ 0.0952, 0.0952, 0.0952, 0.0952, 0.0952],\n",
" [-0.0258, -0.0258, -0.0258, -0.0258, -0.0258],\n",
" [-0.0494, -0.0494, -0.0494, -0.0494, -0.0494],\n",
" [-0.0063, -0.0063, -0.0063, -0.0063, -0.0063],\n",
" [ 0.0318, 0.0318, 0.0318, 0.0318, 0.0318],\n",
" [-0.0824, -0.0824, -0.0824, -0.0824, -0.0824],\n",
" [ 0.0340, 0.0340, 0.0340, 0.0340, 0.0340]])\n"
"tensor([[ 0.0172, 0.0172, 0.0172, 0.0172, 0.0172],\n",
" [ 0.0389, 0.0389, 0.0389, 0.0389, 0.0389],\n",
" [-0.0748, -0.0748, -0.0748, -0.0748, -0.0748],\n",
" [-0.0186, -0.0186, -0.0186, -0.0186, -0.0186],\n",
" [ 0.0278, 0.0278, 0.0278, 0.0278, 0.0278],\n",
" [-0.0228, -0.0228, -0.0228, -0.0228, -0.0228],\n",
" [-0.0496, -0.0496, -0.0496, -0.0496, -0.0496],\n",
" [-0.0084, -0.0084, -0.0084, -0.0084, -0.0084],\n",
" [ 0.0693, 0.0693, 0.0693, 0.0693, 0.0693],\n",
" [-0.0821, -0.0821, -0.0821, -0.0821, -0.0821],\n",
" [ 0.0419, 0.0419, 0.0419, 0.0419, 0.0419],\n",
" [-0.0126, -0.0126, -0.0126, -0.0126, -0.0126],\n",
" [ 0.0322, 0.0322, 0.0322, 0.0322, 0.0322],\n",
" [ 0.0863, 0.0863, 0.0863, 0.0863, 0.0863],\n",
" [-0.0791, -0.0791, -0.0791, -0.0791, -0.0791],\n",
" [ 0.0179, 0.0179, 0.0179, 0.0179, 0.0179],\n",
" [-0.1109, -0.1109, -0.1109, -0.1109, -0.1109],\n",
" [-0.0188, -0.0188, -0.0188, -0.0188, -0.0188],\n",
" [-0.0636, -0.0636, -0.0636, -0.0636, -0.0636],\n",
" [ 0.0223, 0.0223, 0.0223, 0.0223, 0.0223]])\n"
] ]
} }
], ],
@@ -283,7 +295,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 15,
"execution_count": 11,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -304,7 +316,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 16,
"execution_count": 13,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -362,7 +374,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 17,
"execution_count": 14,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -371,7 +383,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 18,
"execution_count": 15,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -417,7 +429,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4,
"execution_count": 20,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -436,7 +448,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5,
"execution_count": 21,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -445,7 +457,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6,
"execution_count": 22,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -462,7 +474,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7,
"execution_count": 23,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -471,7 +483,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8,
"execution_count": 24,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -553,7 +565,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 21,
"execution_count": 29,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -577,7 +589,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 22,
"execution_count": 30,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -606,7 +618,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12,
"execution_count": 31,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -623,7 +635,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 13,
"execution_count": 32,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {


+ 21
- 17
6_pytorch/0_basic/3-dynamic-graph.ipynb View File

@@ -33,9 +33,21 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 15,
"execution_count": 1,
"metadata": {}, "metadata": {},
"outputs": [],
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'tensorflow'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-1-7d11304356bb>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# tensorflow\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32mimport\u001b[0m \u001b[0mtensorflow\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mtf\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mfirst_counter\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconstant\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0msecond_counter\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconstant\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'tensorflow'"
]
}
],
"source": [ "source": [
"# tensorflow\n", "# tensorflow\n",
"import tensorflow as tf\n", "import tensorflow as tf\n",
@@ -134,10 +146,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true
},
"execution_count": 3,
"metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"# pytorch\n", "# pytorch\n",
@@ -148,7 +158,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11,
"execution_count": 5,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -159,21 +169,15 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12,
"execution_count": 6,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"\n",
" 20\n",
"[torch.FloatTensor of size 1]\n",
"\n",
"\n",
" 20\n",
"[torch.FloatTensor of size 1]\n",
"\n"
"tensor([20.])\n",
"tensor([20.])\n"
] ]
} }
], ],
@@ -208,7 +212,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.6.8"
"version": "3.6.9"
} }
}, },
"nbformat": 4, "nbformat": 4,


+ 84
- 84
6_pytorch/1_NN/1-linear-regression-gradient-descend.ipynb
File diff suppressed because it is too large
View File


+ 1
- 1
6_pytorch/1_NN/4-deep-nn.ipynb View File

@@ -688,7 +688,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.6.8"
"version": "3.6.9"
} }
}, },
"nbformat": 4, "nbformat": 4,


+ 1
- 1
6_pytorch/1_NN/5-param_initialize.ipynb View File

@@ -462,7 +462,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.6.8"
"version": "3.6.9"
} }
}, },
"nbformat": 4, "nbformat": 4,


+ 1
- 1
6_pytorch/1_NN/6-nn_summary.ipynb View File

@@ -1947,7 +1947,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.6.8"
"version": "3.6.9"
} }
}, },
"nbformat": 4, "nbformat": 4,


+ 43
- 35
6_pytorch/2_CNN/1-basic_conv.ipynb
File diff suppressed because it is too large
View File


+ 6
- 3
6_pytorch/2_CNN/2-batch-normalization.ipynb View File

@@ -13,11 +13,14 @@
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 数据预处理\n", "## 数据预处理\n",
"目前数据预处理最常见的方法就是中心化和标准化,中心化相当于修正数据的中心位置,实现方法非常简单,就是在每个特征维度上减去对应的均值,最后得到 0 均值的特征。标准化也非常简单,在数据变成 0 均值之后,为了使得不同的特征维度有着相同的规模,可以除以标准差近似为一个标准正态分布,也可以依据最大值和最小值将其转化为 -1 ~ 1 之间,下面是一个简单的图示\n",
"目前数据预处理最常见的方法就是中心化和标准化\n",
"* 中心化相当于修正数据的中心位置,实现方法非常简单,就是在每个特征维度上减去对应的均值,最后得到 0 均值的特征。\n",
"* 标准化也非常简单,在数据变成 0 均值之后,为了使得不同的特征维度有着相同的规模,可以除以标准差近似为一个标准正态分布,也可以依据最大值和最小值将其转化为 -1 ~ 1 之间\n",
"\n", "\n",
"![](https://ws1.sinaimg.cn/large/006tKfTcly1fmqouzer3xj30ij06n0t8.jpg)\n",
"下图是处理的的示例:\n",
"\n", "\n",
"这两种方法非常的常见,如果你还记得,前面我们在神经网络的部分就已经使用了这个方法实现了数据标准化,至于另外一些方法,比如 PCA 或者 白噪声已经用得非常少了。"
"![](images/data_normalize.png)\n",
"\n"
] ]
}, },
{ {


+ 15
- 5
6_pytorch/2_CNN/4-data-augumentation.ipynb View File

@@ -28,10 +28,20 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"metadata": {},
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'torchvision'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-1-eb28cdc1cf7b>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mPIL\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mImage\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0mtorchvision\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mtransforms\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mtfs\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'torchvision'"
]
}
],
"source": [ "source": [
"import sys\n", "import sys\n",
"sys.path.append('..')\n", "sys.path.append('..')\n",
@@ -603,7 +613,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.2"
"version": "3.6.9"
} }
}, },
"nbformat": 4, "nbformat": 4,


+ 1
- 1
6_pytorch/2_CNN/8-resnet.ipynb View File

@@ -373,7 +373,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.6.8"
"version": "3.6.9"
} }
}, },
"nbformat": 4, "nbformat": 4,


BIN
6_pytorch/2_CNN/CNN_Introduction.pptx View File


BIN
6_pytorch/2_CNN/images/data_normalize.png View File

Before After
Width: 666  |  Height: 251  |  Size: 91 kB

+ 4
- 3
README.md View File

@@ -108,7 +108,8 @@


在上述内容学习完成之后,可以进行更进一步机器学习、计算机视觉方面的学习与研究,具体的资料可以参考: 在上述内容学习完成之后,可以进行更进一步机器学习、计算机视觉方面的学习与研究,具体的资料可以参考:
1. 编程是机器学习研究、实现过程非常重要的能力,编程能力弱则无法快速试错,导致研究进度缓慢;如果编程能力强,则可以快速试错,快速编写实验代码等。强烈建议大家在学习本课程之后或之中,好好把数据结构、算法等基本功锻炼一下。具体的教程可以参考[《一步一步学编程》](https://gitee.com/pi-lab/learn_programming) 1. 编程是机器学习研究、实现过程非常重要的能力,编程能力弱则无法快速试错,导致研究进度缓慢;如果编程能力强,则可以快速试错,快速编写实验代码等。强烈建议大家在学习本课程之后或之中,好好把数据结构、算法等基本功锻炼一下。具体的教程可以参考[《一步一步学编程》](https://gitee.com/pi-lab/learn_programming)
2. 智能系统实验室-培训教程与作业:这个教程是实验室积累的机器学习与计算机视觉方面的教程集合,每个课程介绍基本的原理、编程实现、应用方法等资料,可以作为快速入门的学习材料。
- [《智能系统实验室-暑期培训教程》](https://gitee.com/pi-lab/SummerCamp)
- [《智能系统实验室-暑期培训作业》](https://gitee.com/pi-lab/SummerCampHomework)
2. 飞行器智能感知与控制实验室-培训教程与作业:这个教程是实验室积累的机器学习与计算机视觉方面的教程集合,每个课程介绍基本的原理、编程实现、应用方法等资料,可以作为快速入门的学习材料。
- [《飞行器智能感知与控制实验室-暑期培训教程》](https://gitee.com/pi-lab/SummerCamp)
- [《飞行器智能感知与控制实验室-暑期培训作业》](https://gitee.com/pi-lab/SummerCampHomework)
3. 视觉SLAM是一类算法、技巧、编程高度集成的系统,通过学习、练习SLAM能够极大的提高自己的编程、解决问题能力。具体的教程可以参考[《一步一步学SLAM》](https://gitee.com/pi-lab/learn_slam)
3. [《编程代码参考、技巧集合》](https://gitee.com/pi-lab/code_cook):可以在这个代码、技巧集合中找到某项功能的示例,从而加快自己代码的编写 3. [《编程代码参考、技巧集合》](https://gitee.com/pi-lab/code_cook):可以在这个代码、技巧集合中找到某项功能的示例,从而加快自己代码的编写

Loading…
Cancel
Save