Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
b480de5d
M
models
项目概览
PaddlePaddle
/
models
大约 1 年 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
b480de5d
编写于
10月 27, 2020
作者:
Z
Zhang Ting
提交者:
GitHub
10月 27, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Revert "add fuse_bn_add_act_ops args" (#4914)
* Revert "add fuse_bn_add_act_ops args (#4864)"
上级
60d045d3
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
33 addition
and
108 deletion
+33
-108
PaddleCV/image_classification/build_model.py
PaddleCV/image_classification/build_model.py
+1
-6
PaddleCV/image_classification/models/resnet.py
PaddleCV/image_classification/models/resnet.py
+31
-101
PaddleCV/image_classification/utils/utility.py
PaddleCV/image_classification/utils/utility.py
+1
-1
未找到文件。
PaddleCV/image_classification/build_model.py
浏览文件 @
b480de5d
...
...
@@ -39,14 +39,9 @@ def _basic_model(data, model, args, is_train):
image_in
=
fluid
.
layers
.
transpose
(
image
,
[
0
,
2
,
3
,
1
])
if
args
.
data_format
==
'NHWC'
else
image
image_in
.
stop_gradient
=
image
.
stop_gradient
# fuse_bn_add_act only supports amp training
fuse_bn_add_act
=
False
if
is_train
and
args
.
fuse_bn_add_act_ops
:
fuse_bn_add_act
=
True
net_out
=
model
.
net
(
input
=
image_in
,
class_dim
=
args
.
class_dim
,
data_format
=
args
.
data_format
,
fuse_bn_add_act
=
fuse_bn_add_act
)
data_format
=
args
.
data_format
)
else
:
net_out
=
model
.
net
(
input
=
image
,
class_dim
=
args
.
class_dim
)
softmax_out
=
fluid
.
layers
.
softmax
(
net_out
,
use_cudnn
=
False
)
...
...
PaddleCV/image_classification/models/resnet.py
浏览文件 @
b480de5d
...
...
@@ -31,7 +31,7 @@ class ResNet():
def
__init__
(
self
,
layers
=
50
):
self
.
layers
=
layers
def
net
(
self
,
input
,
class_dim
=
1000
,
data_format
=
"NCHW"
,
fuse_bn_add_act
=
False
):
def
net
(
self
,
input
,
class_dim
=
1000
,
data_format
=
"NCHW"
):
layers
=
self
.
layers
supported_layers
=
[
18
,
34
,
50
,
101
,
152
]
assert
layers
in
supported_layers
,
\
...
...
@@ -77,8 +77,7 @@ class ResNet():
num_filters
=
num_filters
[
block
],
stride
=
2
if
i
==
0
and
block
!=
0
else
1
,
name
=
conv_name
,
data_format
=
data_format
,
fuse_bn_add_act
=
fuse_bn_add_act
)
data_format
=
data_format
)
pool
=
fluid
.
layers
.
pool2d
(
input
=
conv
,
pool_type
=
'avg'
,
global_pooling
=
True
,
data_format
=
data_format
)
...
...
@@ -98,8 +97,7 @@ class ResNet():
stride
=
2
if
i
==
0
and
block
!=
0
else
1
,
is_first
=
block
==
i
==
0
,
name
=
conv_name
,
data_format
=
data_format
,
fuse_bn_add_act
=
fuse_bn_add_act
)
data_format
=
data_format
)
pool
=
fluid
.
layers
.
pool2d
(
input
=
conv
,
pool_type
=
'avg'
,
global_pooling
=
True
,
data_format
=
data_format
)
...
...
@@ -157,7 +155,7 @@ class ResNet():
else
:
return
input
def
bottleneck_block
(
self
,
input
,
num_filters
,
stride
,
name
,
data_format
,
fuse_bn_add_act
):
def
bottleneck_block
(
self
,
input
,
num_filters
,
stride
,
name
,
data_format
):
conv0
=
self
.
conv_bn_layer
(
input
=
input
,
num_filters
=
num_filters
,
...
...
@@ -173,56 +171,26 @@ class ResNet():
act
=
'relu'
,
name
=
name
+
"_branch2b"
,
data_format
=
data_format
)
if
not
fuse_bn_add_act
:
conv2
=
self
.
conv_bn_layer
(
input
=
conv1
,
num_filters
=
num_filters
*
4
,
filter_size
=
1
,
act
=
None
,
name
=
name
+
"_branch2c"
,
data_format
=
data_format
)
short
=
self
.
shortcut
(
input
,
num_filters
*
4
,
stride
,
is_first
=
False
,
name
=
name
+
"_branch1"
,
data_format
=
data_format
)
conv2
=
self
.
conv_bn_layer
(
input
=
conv1
,
num_filters
=
num_filters
*
4
,
filter_size
=
1
,
act
=
None
,
name
=
name
+
"_branch2c"
,
data_format
=
data_format
)
return
fluid
.
layers
.
elementwise_add
(
x
=
short
,
y
=
conv2
,
act
=
'relu'
,
name
=
name
+
".add.output.5"
)
else
:
conv2
=
fluid
.
layers
.
conv2d
(
input
=
conv1
,
num_filters
=
num_filters
*
4
,
filter_size
=
1
,
act
=
None
,
param_attr
=
ParamAttr
(
name
=
name
+
"_branch2c"
+
"_weights"
),
bias_attr
=
False
,
name
=
name
+
'_branch2c'
+
'.conv2d.output.1'
,
data_format
=
data_format
)
short
=
self
.
shortcut
(
input
,
num_filters
*
4
,
stride
,
is_first
=
False
,
name
=
name
+
"_branch1"
,
data_format
=
data_format
)
name
=
name
+
"_branch2c"
bn_name
=
"bn"
+
name
[
3
:]
short
=
fluid
.
contrib
.
layers
.
fused_bn_add_act
(
conv2
,
short
,
param_attr
=
ParamAttr
(
name
=
bn_name
+
'_scale'
),
bias_attr
=
ParamAttr
(
bn_name
+
'_offset'
),
moving_mean_name
=
bn_name
+
'_mean'
,
moving_variance_name
=
bn_name
+
'_variance'
,
name
=
name
+
".add.output.5"
)
short
=
self
.
shortcut
(
input
,
num_filters
*
4
,
stride
,
is_first
=
False
,
name
=
name
+
"_branch1"
,
data_format
=
data_format
)
return
short
return
fluid
.
layers
.
elementwise_add
(
x
=
short
,
y
=
conv2
,
act
=
'relu'
,
name
=
name
+
".add.output.5"
)
def
basic_block
(
self
,
input
,
num_filters
,
stride
,
is_first
,
name
,
data_format
,
fuse_bn_add_act
):
def
basic_block
(
self
,
input
,
num_filters
,
stride
,
is_first
,
name
,
data_format
):
conv0
=
self
.
conv_bn_layer
(
input
=
input
,
num_filters
=
num_filters
,
...
...
@@ -231,54 +199,16 @@ class ResNet():
stride
=
stride
,
name
=
name
+
"_branch2a"
,
data_format
=
data_format
)
if
not
fuse_bn_add_act
:
conv1
=
self
.
conv_bn_layer
(
input
=
conv0
,
num_filters
=
num_filters
,
filter_size
=
3
,
act
=
None
,
name
=
name
+
"_branch2b"
,
data_format
=
data_format
)
short
=
self
.
shortcut
(
input
,
num_filters
,
stride
,
is_first
,
name
=
name
+
"_branch1"
,
data_format
=
data_format
)
return
fluid
.
layers
.
elementwise_add
(
x
=
short
,
y
=
conv1
,
act
=
'relu'
)
else
:
conv1
=
fluid
.
layers
.
conv2d
(
input
=
conv0
,
num_filters
=
num_filters
,
filter_size
=
3
,
stride
=
1
,
padding
=
1
,
groups
=
1
,
act
=
None
,
param_attr
=
ParamAttr
(
name
=
name
+
"_weights"
),
bias_attr
=
False
,
name
=
name
+
'_branch2b'
+
'.conv2d.output.1'
,
data_format
=
data_format
)
short
=
self
.
shortcut
(
input
,
num_filters
,
stride
,
is_first
,
name
=
name
+
"_branch1"
,
data_format
=
data_format
)
name
=
name
+
"_branch2b"
bn_name
=
"bn"
+
name
[
3
:]
short
=
fluid
.
contrib
.
layers
.
fused_bn_add_act
(
conv1
,
short
,
param_attr
=
ParamAttr
(
name
=
bn_name
+
'_scale'
),
bias_attr
=
ParamAttr
(
bn_name
+
'_offset'
),
moving_mean_name
=
bn_name
+
'_mean'
,
moving_variance_name
=
bn_name
+
'_variance'
)
return
short
conv1
=
self
.
conv_bn_layer
(
input
=
conv0
,
num_filters
=
num_filters
,
filter_size
=
3
,
act
=
None
,
name
=
name
+
"_branch2b"
,
data_format
=
data_format
)
short
=
self
.
shortcut
(
input
,
num_filters
,
stride
,
is_first
,
name
=
name
+
"_branch1"
,
data_format
=
data_format
)
return
fluid
.
layers
.
elementwise_add
(
x
=
short
,
y
=
conv1
,
act
=
'relu'
)
def
ResNet18
():
...
...
PaddleCV/image_classification/utils/utility.py
浏览文件 @
b480de5d
...
...
@@ -147,7 +147,7 @@ def parse_args():
add_arg
(
'fuse_bn_act_ops'
,
bool
,
False
,
"Whether to use batch_norm and act fusion."
)
add_arg
(
'fuse_bn_add_act_ops'
,
bool
,
False
,
"Whether to use batch_norm, elementwise_add and act fusion. This is only used for AMP training."
)
add_arg
(
'enable_addto'
,
bool
,
False
,
"Whether to enable the addto strategy for gradient accumulation or not. This is only used for AMP training."
)
add_arg
(
'use_label_smoothing'
,
bool
,
False
,
"Whether to use label_smoothing"
)
add_arg
(
'label_smoothing_epsilon'
,
float
,
0.1
,
"The value of label_smoothing_epsilon parameter"
)
#NOTE: (2019/08/08) temporary disable use_distill
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录