Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
7b4cb655
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
7b4cb655
编写于
10月 31, 2019
作者:
L
liym27
提交者:
石晓伟
10月 31, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
keep the size of symmetric padding is 2 for 2d and 3 for 3d. test=develop (#20903)
上级
8d1e9f0f
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
41 addition
and
16 deletion
+41
-16
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+28
-16
python/paddle/fluid/layers/utils.py
python/paddle/fluid/layers/utils.py
+13
-0
未找到文件。
python/paddle/fluid/layers/nn.py
浏览文件 @
7b4cb655
...
...
@@ -2745,9 +2745,11 @@ def conv2d(input,
padding = padding[1:3]
padding = [ele for a_list in padding for ele in a_list]
padding = utils.convert_to_list(padding, 4, 'padding')
if utils._is_symmetric_padding(padding, 2):
padding = [padding[0], padding[2]]
else:
padding = utils.convert_to_list(padding, 2, 'padding')
padding = [padding[0], padding[0], padding[1], padding[1]]
return padding
...
...
@@ -2760,10 +2762,10 @@ def conv2d(input,
str(padding))
if padding == "VALID":
padding_algorithm = "VALID"
padding = [0, 0
, 0, 0
]
padding = [0, 0]
elif padding == "SAME":
padding_algorithm = "SAME"
padding = [0, 0
, 0, 0
]
padding = [0, 0]
padding = _update_padding(padding, data_format)
...
...
@@ -2989,15 +2991,14 @@ def conv3d(input,
padding = padding[1:4]
padding = [ele for a_list in padding for ele in a_list]
padding = utils.convert_to_list(padding, 6, 'padding')
if utils._is_symmetric_padding(padding, 3):
padding = [padding[0], padding[2], padding[4]]
elif is_list_or_tuple(padding) and len(padding) == 6:
padding = utils.convert_to_list(padding, 6, 'padding')
if utils._is_symmetric_padding(padding, 3):
padding = [padding[0], padding[2], padding[4]]
else:
padding = utils.convert_to_list(padding, 3, 'padding')
padding = [
padding[0], padding[0], padding[1], padding[1], padding[2],
padding[2]
]
return padding
...
...
@@ -3010,10 +3011,10 @@ def conv3d(input,
str(padding))
if padding == "VALID":
padding_algorithm = "VALID"
padding = [0, 0, 0
, 0, 0, 0
]
padding = [0, 0, 0]
elif padding == "SAME":
padding_algorithm = "SAME"
padding = [0, 0, 0
, 0, 0, 0
]
padding = [0, 0, 0]
padding = _update_padding(padding, data_format)
...
...
@@ -3556,6 +3557,8 @@ def pool2d(input,
padding = [ele for a_list in padding for ele in a_list]
padding = utils.convert_to_list(padding, 4, 'padding')
if utils._is_symmetric_padding(padding, 2):
padding = [padding[0], padding[2]]
else:
padding = utils.convert_to_list(padding, 2, 'padding')
...
...
@@ -3570,14 +3573,14 @@ def pool2d(input,
% str(pool_padding))
if pool_padding == "VALID":
padding_algorithm = "VALID"
pool_padding = [0, 0
, 0, 0
]
pool_padding = [0, 0]
if ceil_mode != False:
raise ValueError(
"When Attr(pool_padding) is \"VALID\", Attr(ceil_mode) must be False. "
"Received ceil_mode: True.")
elif pool_padding == "SAME":
padding_algorithm = "SAME"
pool_padding = [0, 0
, 0, 0
]
pool_padding = [0, 0]
pool_padding = update_padding(pool_padding, data_format)
...
...
@@ -3760,10 +3763,13 @@ def pool3d(input,
padding = padding[1:4]
padding = [ele for a_list in padding for ele in a_list]
padding = utils.convert_to_list(padding, 6, 'padding')
if utils._is_symmetric_padding(padding, 3):
padding = [padding[0], padding[2], padding[4]]
elif is_list_or_tuple(padding) and len(padding) == 6:
padding = utils.convert_to_list(padding, 6, 'padding')
if utils._is_symmetric_padding(padding, 3):
padding = [padding[0], padding[2], padding[4]]
else:
padding = utils.convert_to_list(padding, 3, 'padding')
...
...
@@ -3778,14 +3784,14 @@ def pool3d(input,
% str(pool_padding))
if pool_padding == "VALID":
padding_algorithm = "VALID"
pool_padding = [0, 0, 0
, 0, 0, 0
]
pool_padding = [0, 0, 0]
if ceil_mode != False:
raise ValueError(
"When Attr(pool_padding) is \"VALID\", ceil_mode must be False. "
"Received ceil_mode: True.")
elif pool_padding == "SAME":
padding_algorithm = "SAME"
pool_padding = [0, 0, 0
, 0, 0, 0
]
pool_padding = [0, 0, 0]
pool_padding = update_padding(pool_padding, data_format)
...
...
@@ -5125,6 +5131,9 @@ def conv2d_transpose(input,
filter_size = utils.convert_to_list(filter_size, 2,
'conv2d_transpose.filter_size')
if len(padding) == 4 and utils._is_symmetric_padding(padding, 2):
padding = [padding[0], padding[2]]
if output_size is None:
output_size = []
elif isinstance(output_size, list) or isinstance(output_size, int):
...
...
@@ -5360,13 +5369,13 @@ def conv3d_transpose(input,
elif is_list_or_tuple(padding) and len(padding) == 6:
padding = utils.convert_to_list(padding, 6, 'padding')
else:
padding = utils.convert_to_list(padding, 3, 'padding')
padding = [
padding[0], padding[0], padding[1], padding[1], padding[2],
padding[2]
]
return padding
padding_algorithm = "EXPLICIT"
...
...
@@ -5406,6 +5415,9 @@ def conv3d_transpose(input,
filter_size = utils.convert_to_list(filter_size, 3,
'conv3d_transpose.filter_size')
if len(padding) == 6 and utils._is_symmetric_padding(padding, 3):
padding = [padding[0], padding[2], padding[4]]
groups = 1 if groups is None else groups
filter_shape = [input_channel, num_filters // groups] + filter_size
img_filter = helper.create_parameter(
...
...
python/paddle/fluid/layers/utils.py
浏览文件 @
7b4cb655
...
...
@@ -231,3 +231,16 @@ def assert_same_structure(nest1, nest2, check_types=True):
"Second structure (%i elements): %s"
%
(
len_nest1
,
nest1
,
len_nest2
,
nest2
))
_recursive_assert_same_structure
(
nest1
,
nest2
,
check_types
)
def
_is_symmetric_padding
(
padding
,
data_dim
):
"""
Check whether padding is symmetrical.
"""
assert
len
(
padding
)
==
data_dim
*
2
or
len
(
padding
)
==
data_dim
is_sys
=
True
if
len
(
padding
)
==
data_dim
*
2
:
for
i
in
range
(
data_dim
):
if
padding
[
i
*
2
]
!=
padding
[
i
*
2
+
1
]:
is_sys
=
False
return
is_sys
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录