Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
d2l-zh
提交
5cf92b0a
D
d2l-zh
项目概览
OpenDocCN
/
d2l-zh
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
d2l-zh
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
5cf92b0a
编写于
10月 14, 2017
作者:
M
Mu Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update fine-tuning
上级
f0050cc3
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
9 addition
and
10 deletion
+9
-10
chapter_computer-vision/fine-tuning.md
chapter_computer-vision/fine-tuning.md
+9
-10
未找到文件。
chapter_computer-vision/fine-tuning.md
浏览文件 @
5cf92b0a
#
Fine
tuning: 通过微调来迁移学习
#
【草稿】Fine-
tuning: 通过微调来迁移学习
【代码完成,但文字还没翻译完】
...
...
@@ -97,7 +97,7 @@ random negative)
-
not_hotdog_validation.rec 49M (209 positive, 700 interesting negative, and 350
random negative)
```
{.python .input n=
2
}
```
{.python .input n=
1
}
dataset = {'train': ('not_hotdog_train-e6ef27b4.rec', '0aad7e1f16f5fb109b719a414a867bbee6ef27b4'),
'validation': ('not_hotdog_validation-c0201740.rec', '723ae5f8a433ed2e2bf729baec6b878ac0201740')}
...
...
@@ -108,7 +108,7 @@ But if you're interested in training on the full set,
set 'demo' to False in the settings at the beginning.
Now we're ready to download and verify the dataset.
```
{.python .input n=
3
}
```
{.python .input n=
2
}
from mxnet import gluon
base_url = 'https://apache-mxnet.s3-accelerate.amazonaws.com/gluon/dataset/'
download_dir = '../data/'
...
...
@@ -125,7 +125,7 @@ get_file(*dataset['validation'])
The record files can be read using
[
mx.io.ImageRecordIter
](
http://mxnet.io/api/p
ython/io.html#mxnet.io.ImageRecordIter)
```
{.python .input n=
4
}
```
{.python .input n=
3
}
from mxnet import io
train_iter = io.ImageRecordIter(
...
...
@@ -151,7 +151,7 @@ val_iter = io.ImageRecordIter(
这里我们将使用Gluon提供的ResNet18来训练。我们先从模型园里获取改良过ResNet。使用
`pretrained=True`
将会自动下载并加载从ImageNet数据集上训练而来的权重。
```
{.python .input}
```
{.python .input
n=4
}
from mxnet.gluon.model_zoo import vision as models
pretrained_net = models.resnet18_v2(pretrained=True)
...
...
@@ -160,13 +160,13 @@ pretrained_net
可以看到这个模型有两部分组成,一是
`features`
,二是
`classifier`
。后者主要包括最后一层全连接层。我们可以看一下第一个卷积层的部分权重。
```
{.python .input}
```
{.python .input
n=5
}
pretrained_net.features[1].params.get('weight').data()[0][0]
```
在微调里,我们一般新建一个网络,它的定义跟之前训练好的网络一样,除了最后的输出数等于当前数据的类别数。新网络的
`features`
被初始化前面训练好网络的权重,而
`classfier`
则是从头开始训练。
```
{.python .input}
```
{.python .input
n=6
}
from mxnet import init
finetune_net = models.resnet18_v2(classes=2)
...
...
@@ -199,7 +199,7 @@ def train(net, ctx, epochs=2, learning_rate=0.1, wd=0.001):
```
{.python .input}
ctx = utils.try_gpu()
train(finetune_net, ctx,
learning_rate=0.01, epochs=4
)
train(finetune_net, ctx,
epochs=5
)
```
对比起见我们尝试从随机初始值开始训练一个网络
...
...
@@ -249,7 +249,7 @@ classify_hotdog(finetune_net, '../img/real_hotdog.jpg')
```
```
{.python .input n=18}
classify_hotdog(
scratch
_net, '../img/leg_hotdog.jpg')
classify_hotdog(
finetune
_net, '../img/leg_hotdog.jpg')
```
```
{.python .input n=19}
...
...
@@ -279,4 +279,3 @@ so that you can just perform fine-tuning on the task at hand.
```
试试重用
`classifer`
里重用hotdog的权重
-
试试不让
`finetune_net`
里重用的权重参与训练,就是不更新权重
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录