Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MindSpore
docs
提交
dd5a04a2
D
docs
项目概览
MindSpore
/
docs
通知
5
Star
3
Fork
2
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
dd5a04a2
编写于
8月 29, 2020
作者:
C
chenfei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change network definition of lenet in tutorials
上级
650b40d7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
49 addition
and
25 deletion
+49
-25
tutorials/source_zh_cn/advanced_use/quantization_aware.md
tutorials/source_zh_cn/advanced_use/quantization_aware.md
+49
-25
未找到文件。
tutorials/source_zh_cn/advanced_use/quantization_aware.md
浏览文件 @
dd5a04a2
...
@@ -82,47 +82,71 @@ MindSpore的感知量化训练是在训练基础上,使用低精度数据替
...
@@ -82,47 +82,71 @@ MindSpore的感知量化训练是在训练基础上,使用低精度数据替
定义融合网络,在定义网络后,替换指定的算子。
定义融合网络,在定义网络后,替换指定的算子。
1.
使用
`nn.Conv2dBnAct`
算子替换原网络模型中的
3个算子
`nn.Conv2d`
、
`nn.batchnorm`
和
`nn.r
elu`
。
1.
使用
`nn.Conv2dBnAct`
算子替换原网络模型中的
2个算子
`nn.Conv2d`
、和
`nn.R
elu`
。
2.
使用
`nn.DenseBnAct`
算子替换原网络模型中的
3个算子
`nn.Dense`
、
`nn.batchnorm`
和
`nn.r
elu`
。
2.
使用
`nn.DenseBnAct`
算子替换原网络模型中的
2个算子
`nn.Dense`
、和
`nn.R
elu`
。
>
即使`nn.Dense`和`nn.Conv2d`算子后面没有`nn.batchnorm`和`nn.r
elu`,都要按规定使用上述两个算子进行融合替换。
>
无论`nn.Dense`和`nn.Conv2d`算子后面有没有`nn.BatchNorm`和`nn.R
elu`,都要按规定使用上述两个算子进行融合替换。
原网络模型的定义如下所示:
原网络模型
LeNet5
的定义如下所示:
```
python
```
python
def
conv
(
in_channels
,
out_channels
,
kernel_size
,
stride
=
1
,
padding
=
0
):
"""weight initial for conv layer"""
weight
=
weight_variable
()
return
nn
.
Conv2d
(
in_channels
,
out_channels
,
kernel_size
=
kernel_size
,
stride
=
stride
,
padding
=
padding
,
weight_init
=
weight
,
has_bias
=
False
,
pad_mode
=
"valid"
)
def
fc_with_initialize
(
input_channels
,
out_channels
):
"""weight initial for fc layer"""
weight
=
weight_variable
()
bias
=
weight_variable
()
return
nn
.
Dense
(
input_channels
,
out_channels
,
weight
,
bias
)
def
weight_variable
():
"""weight initial"""
return
TruncatedNormal
(
0.02
)
class
LeNet5
(
nn
.
Cell
):
class
LeNet5
(
nn
.
Cell
):
def
__init__
(
self
,
num_class
=
10
):
"""
Lenet network
Args:
num_class (int): Num classes. Default: 10.
Returns:
Tensor, output tensor
Examples:
>>> LeNet(num_class=10)
"""
def
__init__
(
self
,
num_class
=
10
,
channel
=
1
):
super
(
LeNet5
,
self
).
__init__
()
super
(
LeNet5
,
self
).
__init__
()
self
.
num_class
=
num_class
self
.
num_class
=
num_class
self
.
conv1
=
conv
(
channel
,
6
,
5
)
self
.
conv1
=
nn
.
Conv2d
(
1
,
6
,
kernel_size
=
5
)
self
.
conv2
=
conv
(
6
,
16
,
5
)
self
.
bn1
=
nn
.
batchnorm
(
6
)
self
.
fc1
=
fc_with_initialize
(
16
*
5
*
5
,
120
)
self
.
act1
=
nn
.
relu
()
self
.
fc2
=
fc_with_initialize
(
120
,
84
)
self
.
fc3
=
fc_with_initialize
(
84
,
self
.
num_class
)
self
.
conv2
=
nn
.
Conv2d
(
6
,
16
,
kernel_size
=
5
)
self
.
relu
=
nn
.
ReLU
()
self
.
bn2
=
nn
.
batchnorm
(
16
)
self
.
act2
=
nn
.
relu
()
self
.
fc1
=
nn
.
Dense
(
16
*
5
*
5
,
120
)
self
.
fc2
=
nn
.
Dense
(
120
,
84
)
self
.
act3
=
nn
.
relu
()
self
.
fc3
=
nn
.
Dense
(
84
,
self
.
num_class
)
self
.
max_pool2d
=
nn
.
MaxPool2d
(
kernel_size
=
2
,
stride
=
2
)
self
.
max_pool2d
=
nn
.
MaxPool2d
(
kernel_size
=
2
,
stride
=
2
)
self
.
flatten
=
nn
.
Flatten
()
def
construct
(
self
,
x
):
def
construct
(
self
,
x
):
x
=
self
.
conv1
(
x
)
x
=
self
.
conv1
(
x
)
x
=
self
.
bn1
(
x
)
x
=
self
.
relu
(
x
)
x
=
self
.
act1
(
x
)
x
=
self
.
max_pool2d
(
x
)
x
=
self
.
max_pool2d
(
x
)
x
=
self
.
conv2
(
x
)
x
=
self
.
conv2
(
x
)
x
=
self
.
bn2
(
x
)
x
=
self
.
relu
(
x
)
x
=
self
.
act2
(
x
)
x
=
self
.
max_pool2d
(
x
)
x
=
self
.
max_pool2d
(
x
)
x
=
self
.
flatte
r
n
(
x
)
x
=
self
.
flatten
(
x
)
x
=
self
.
fc1
(
x
)
x
=
self
.
fc1
(
x
)
x
=
self
.
act3
(
x
)
x
=
self
.
relu
(
x
)
x
=
self
.
fc2
(
x
)
x
=
self
.
fc2
(
x
)
x
=
self
.
act3
(
x
)
x
=
self
.
relu
(
x
)
x
=
self
.
fc3
(
x
)
x
=
self
.
fc3
(
x
)
return
x
return
x
```
```
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录