Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
46700bec
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
46700bec
编写于
6月 23, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
6月 23, 2020
浏览文件
操作
浏览文件
下载
差异文件
!2500 add output activation quant in mobilenetv2 and resnet50
Merge pull request !2500 from chenzupeng/r0.3
上级
3a40ac65
bf067300
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
15 addition
and
6 deletion
+15
-6
example/mobilenetv2_quant/src/mobilenetV2_quant.py
example/mobilenetv2_quant/src/mobilenetV2_quant.py
+4
-2
example/resnet50_quant/models/resnet_quant.py
example/resnet50_quant/models/resnet_quant.py
+11
-4
未找到文件。
example/mobilenetv2_quant/src/mobilenetV2_quant.py
浏览文件 @
46700bec
...
...
@@ -193,10 +193,12 @@ class MobileNetV2Quant(nn.Cell):
# mobilenet head
head
=
([
GlobalAvgPooling
(),
nn
.
DenseQuant
(
self
.
out_channels
,
num_classes
,
has_bias
=
True
,
per_channel
=
_per_channel
,
symmetric
=
_symmetric
)]
if
not
has_dropout
else
symmetric
=
_symmetric
),
nn
.
FakeQuantWithMinMax
(
ema
=
True
,
ema_decay
=
_ema_decay
)]
if
not
has_dropout
else
[
GlobalAvgPooling
(),
nn
.
Dropout
(
0.2
),
nn
.
DenseQuant
(
self
.
out_channels
,
num_classes
,
has_bias
=
True
,
per_channel
=
_per_channel
,
symmetric
=
_symmetric
)])
symmetric
=
_symmetric
),
nn
.
FakeQuantWithMinMax
(
ema
=
True
,
ema_decay
=
_ema_decay
)])
self
.
head
=
nn
.
SequentialCell
(
head
)
def
construct
(
self
,
x
):
...
...
example/resnet50_quant/models/resnet_quant.py
浏览文件 @
46700bec
...
...
@@ -24,6 +24,7 @@ _symmetric = False
_fake
=
True
_per_channel
=
True
def
_weight_variable
(
shape
,
factor
=
0.01
):
init_value
=
np
.
random
.
randn
(
*
shape
).
astype
(
np
.
float32
)
*
factor
return
Tensor
(
init_value
)
...
...
@@ -65,6 +66,7 @@ def _fc(in_channel, out_channel):
weight
=
_weight_variable
(
weight_shape
)
return
nn
.
Dense
(
in_channel
,
out_channel
,
has_bias
=
True
,
weight_init
=
weight
,
bias_init
=
0
)
class
ConvBNReLU
(
nn
.
Cell
):
"""
Convolution/Depthwise fused with Batchnorm and ReLU block definition.
...
...
@@ -82,6 +84,7 @@ class ConvBNReLU(nn.Cell):
Examples:
>>> ConvBNReLU(16, 256, kernel_size=1, stride=1, groups=1)
"""
def
__init__
(
self
,
in_planes
,
out_planes
,
kernel_size
=
3
,
stride
=
1
,
groups
=
1
):
super
(
ConvBNReLU
,
self
).
__init__
()
padding
=
(
kernel_size
-
1
)
//
2
...
...
@@ -94,6 +97,7 @@ class ConvBNReLU(nn.Cell):
output
=
self
.
features
(
x
)
return
output
class
ResidualBlock
(
nn
.
Cell
):
"""
ResNet V1 residual block definition.
...
...
@@ -152,8 +156,8 @@ class ResidualBlock(nn.Cell):
stride
=
stride
,
pad_mode
=
'same'
,
padding
=
0
)
self
.
add
=
P
.
TensorAdd
()
self
.
relu
=
nn
.
ReLUQuant
()
if
_fake
else
P
.
ReLU
()
self
.
add
=
nn
.
TensorAddQuant
()
self
.
relu
=
P
.
ReLU
()
def
construct
(
self
,
x
):
identity
=
x
...
...
@@ -231,7 +235,9 @@ class ResNet(nn.Cell):
self
.
mean
=
P
.
ReduceMean
(
keep_dims
=
True
)
self
.
flatten
=
nn
.
Flatten
()
self
.
end_point
=
nn
.
Dense
(
out_channels
[
3
],
num_classes
,
has_bias
=
True
)
self
.
end_point
=
nn
.
DenseQuant
(
out_channels
[
3
],
num_classes
,
has_bias
=
True
,
per_channel
=
_per_channel
,
symmetric
=
_symmetric
)
self
.
output_fake
=
nn
.
FakeQuantWithMinMax
(
ema
=
True
,
ema_decay
=
_ema_decay
)
def
_make_layer
(
self
,
block
,
layer_num
,
in_channel
,
out_channel
,
stride
):
"""
...
...
@@ -273,7 +279,7 @@ class ResNet(nn.Cell):
out
=
self
.
mean
(
c5
,
(
2
,
3
))
out
=
self
.
flatten
(
out
)
out
=
self
.
end_point
(
out
)
out
=
self
.
output_fake
(
out
)
return
out
...
...
@@ -297,6 +303,7 @@ def resnet50_quant(class_num=10):
[
1
,
2
,
2
,
2
],
class_num
)
def
resnet101_quant
(
class_num
=
1001
):
"""
Get ResNet101 neural network.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录