Browse Source

Improve some contents

pull/15/head
bushuhui 3 years ago
parent
commit
45d8f39e0b
8 changed files with 62 additions and 31 deletions
  1. +10
    -4
      4_logistic_regression/2-Logistic_regression.ipynb
  2. +10
    -4
      7_deep_learning/1_CNN/03-AlexNet.ipynb
  3. +11
    -6
      7_deep_learning/1_CNN/05-googlenet.ipynb
  4. +19
    -12
      7_deep_learning/1_CNN/07-densenet.ipynb
  5. +9
    -2
      7_deep_learning/1_CNN/08-batch-normalization.ipynb
  6. +1
    -1
      7_deep_learning/1_CNN/09-lr-decay.ipynb
  7. +1
    -1
      7_deep_learning/1_CNN/10-regularization.ipynb
  8. +1
    -1
      7_deep_learning/1_CNN/11-data-augumentation.ipynb

+ 10
- 4
4_logistic_regression/2-Logistic_regression.ipynb View File

@@ -181,7 +181,9 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%matplotlib inline\n",
@@ -234,7 +236,9 @@
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def plot_decision_boundary(predict_func, data, label, figName=None):\n",
@@ -263,7 +267,9 @@
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"\n",
@@ -780,7 +786,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.9"
"version": "3.5.4"
}
},
"nbformat": 4,


+ 10
- 4
7_deep_learning/1_CNN/03-AlexNet.ipynb View File

@@ -13,7 +13,9 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import torch.nn as nn\n",
@@ -97,7 +99,9 @@
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from torchvision.datasets import CIFAR10\n",
@@ -216,7 +220,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# save raw data\n",
@@ -241,7 +247,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.9"
"version": "3.5.4"
}
},
"nbformat": 4,


+ 11
- 6
7_deep_learning/1_CNN/05-googlenet.ipynb View File

@@ -42,7 +42,8 @@
"ExecuteTime": {
"end_time": "2017-12-22T12:51:05.427292Z",
"start_time": "2017-12-22T12:51:04.924747Z"
}
},
"collapsed": true
},
"outputs": [],
"source": [
@@ -61,7 +62,8 @@
"ExecuteTime": {
"end_time": "2017-12-22T12:51:08.890890Z",
"start_time": "2017-12-22T12:51:08.876313Z"
}
},
"collapsed": true
},
"outputs": [],
"source": [
@@ -82,7 +84,8 @@
"ExecuteTime": {
"end_time": "2017-12-22T12:51:09.671474Z",
"start_time": "2017-12-22T12:51:09.587337Z"
}
},
"collapsed": true
},
"outputs": [],
"source": [
@@ -167,7 +170,8 @@
"ExecuteTime": {
"end_time": "2017-12-22T12:51:13.149380Z",
"start_time": "2017-12-22T12:51:12.934110Z"
}
},
"collapsed": true
},
"outputs": [],
"source": [
@@ -280,7 +284,8 @@
"ExecuteTime": {
"end_time": "2017-12-22T12:51:16.387778Z",
"start_time": "2017-12-22T12:51:15.121350Z"
}
},
"collapsed": true
},
"outputs": [],
"source": [
@@ -447,7 +452,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.9"
"version": "3.5.4"
}
},
"nbformat": 4,


+ 19
- 12
7_deep_learning/1_CNN/07-densenet.ipynb View File

@@ -45,7 +45,8 @@
"ExecuteTime": {
"end_time": "2017-12-22T15:38:31.113030Z",
"start_time": "2017-12-22T15:38:30.612922Z"
}
},
"collapsed": true
},
"outputs": [],
"source": [
@@ -71,7 +72,8 @@
"ExecuteTime": {
"end_time": "2017-12-22T15:38:31.121249Z",
"start_time": "2017-12-22T15:38:31.115369Z"
}
},
"collapsed": true
},
"outputs": [],
"source": [
@@ -98,7 +100,8 @@
"ExecuteTime": {
"end_time": "2017-12-22T15:38:31.145274Z",
"start_time": "2017-12-22T15:38:31.123363Z"
}
},
"collapsed": true
},
"outputs": [],
"source": [
@@ -168,11 +171,12 @@
"ExecuteTime": {
"end_time": "2017-12-22T15:38:31.222120Z",
"start_time": "2017-12-22T15:38:31.215770Z"
}
},
"collapsed": true
},
"outputs": [],
"source": [
"def transition(in_channel, out_channel):\n",
"def Transition_Block(in_channel, out_channel):\n",
" trans_layer = nn.Sequential(\n",
" nn.BatchNorm2d(in_channel),\n",
" nn.ReLU(True),\n",
@@ -209,7 +213,7 @@
}
],
"source": [
"test_net = transition(3, 12)\n",
"test_net = Transition_Block(3, 12)\n",
"test_x = Variable(torch.zeros(1, 3, 96, 96))\n",
"print('input shape: {} x {} x {}'.format(test_x.shape[1], test_x.shape[2], test_x.shape[3]))\n",
"test_y = test_net(test_x)\n",
@@ -232,7 +236,8 @@
"ExecuteTime": {
"end_time": "2017-12-22T15:38:31.318822Z",
"start_time": "2017-12-22T15:38:31.236857Z"
}
},
"collapsed": true
},
"outputs": [],
"source": [
@@ -240,10 +245,11 @@
" def __init__(self, in_channel, num_classes, growth_rate=32, block_layers=[6, 12, 24, 16]):\n",
" super(DenseNet, self).__init__()\n",
" self.block1 = nn.Sequential(\n",
" nn.Conv2d(in_channel, 64, 7, 2, 3),\n",
" nn.Conv2d(in_channels=in_channel, out_channels=64, \n",
" kernel_size=7, stride=2, padding=3),\n",
" nn.BatchNorm2d(64),\n",
" nn.ReLU(True),\n",
" nn.MaxPool2d(3, 2, padding=1)\n",
" nn.MaxPool2d(kernel_size=3, stride=2, padding=1)\n",
" )\n",
" \n",
" channels = 64\n",
@@ -252,7 +258,7 @@
" block.append(Dense_Block(channels, growth_rate, layers))\n",
" channels += layers * growth_rate\n",
" if i != len(block_layers) - 1:\n",
" block.append(transition(channels, channels // 2)) # 通过 transition 层将大小减半,通道数减半\n",
" block.append(Transition_Block(channels, channels // 2)) # 通过 transition 层将大小减半,通道数减半\n",
" channels = channels // 2\n",
" \n",
" self.block2 = nn.Sequential(*block)\n",
@@ -303,7 +309,8 @@
"ExecuteTime": {
"end_time": "2017-12-22T15:38:32.894729Z",
"start_time": "2017-12-22T15:38:31.656356Z"
}
},
"collapsed": true
},
"outputs": [],
"source": [
@@ -458,7 +465,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.9"
"version": "3.5.4"
}
},
"nbformat": 4,


+ 9
- 2
7_deep_learning/1_CNN/08-batch-normalization.ipynb View File

@@ -59,7 +59,7 @@
"source": [
"* 第一和第二个公式计算出一个 batch 中数据的均值和方差\n",
"* 第三个公式对 batch 中的每个数据点做标准化,$\\epsilon$ 是为了计算稳定引入的一个小的常数,通常取 $10^{-5}$\n",
"* 最后利用权重修正得到最后的输出结果,其中 $\\gamma$ $\\beta$是权值变换参数,也是网络参数在训练过程一起学习\n",
"* 最后利用权重修正得到最后的输出结果,其中 $\\gamma$$\\beta$是权值变换参数,也是网络参数在训练过程一起学习\n",
"\n",
"下面演示一维的情况,也就是神经网络中的情况"
]
@@ -427,6 +427,13 @@
"下面我们在卷积网络下试用一下批标准化看看效果"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"FIXME:设计一个更有说服力的例子"
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -588,7 +595,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.9"
"version": "3.5.4"
}
},
"nbformat": 4,


+ 1
- 1
7_deep_learning/1_CNN/09-lr-decay.ipynb View File

@@ -267,7 +267,7 @@
" if epoch == 20:\n",
" set_learning_rate(optimizer, 0.01) # 20 次修改学习率为 0.01\n",
" elif epoch == 60:\n",
" set_learning_rate(optimizer, 0.005) # 60 次修改学习率为 0.01\n",
" set_learning_rate(optimizer, 0.005) # 60 次修改学习率为 0.005\n",
"\n",
" train_loss = 0\n",
" net = net.train()\n",


+ 1
- 1
7_deep_learning/1_CNN/10-regularization.ipynb View File

@@ -160,7 +160,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.9"
"version": "3.5.4"
}
},
"nbformat": 4,


+ 1
- 1
7_deep_learning/1_CNN/11-data-augumentation.ipynb View File

@@ -612,7 +612,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.9"
"version": "3.5.4"
}
},
"nbformat": 4,


Loading…
Cancel
Save