Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
96331f74
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看板
未验证
提交
96331f74
编写于
9月 03, 2020
作者:
L
LielinJiang
提交者:
GitHub
9月 03, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix conv1d padding (#26921)
上级
95e1434b
变更
4
展开全部
隐藏空白更改
内联
并排
Showing
4 changed file
with
237 addition
and
265 deletion
+237
-265
python/paddle/fluid/tests/unittests/test_conv1d_layer.py
python/paddle/fluid/tests/unittests/test_conv1d_layer.py
+11
-2
python/paddle/fluid/tests/unittests/test_conv1d_transpose_layer.py
...ddle/fluid/tests/unittests/test_conv1d_transpose_layer.py
+1
-0
python/paddle/nn/functional/conv.py
python/paddle/nn/functional/conv.py
+34
-28
python/paddle/nn/layer/conv.py
python/paddle/nn/layer/conv.py
+191
-235
未找到文件。
python/paddle/fluid/tests/unittests/test_conv1d_layer.py
浏览文件 @
96331f74
...
...
@@ -44,7 +44,7 @@ class Conv1dTestCase(unittest.TestCase):
self
.
spartial_shape
=
spartial_shape
self
.
filter_size
=
filter_size
self
.
data_format
=
data_format
self
.
channel_last
=
(
self
.
data_format
==
"N
HW
C"
)
self
.
channel_last
=
(
self
.
data_format
==
"N
L
C"
)
self
.
padding
=
padding
self
.
padding_mode
=
padding_mode
...
...
@@ -147,6 +147,14 @@ class Conv1dErrorTestCase(Conv1dTestCase):
self
.
paddle_nn_layer
()
class
Conv1dTypeErrorTestCase
(
Conv1dTestCase
):
def
runTest
(
self
):
place
=
fluid
.
CPUPlace
()
with
dg
.
guard
(
place
):
with
self
.
assertRaises
(
TypeError
):
self
.
paddle_nn_layer
()
def
add_cases
(
suite
):
suite
.
addTest
(
Conv1dTestCase
(
methodName
=
'runTest'
))
suite
.
addTest
(
Conv1dTestCase
(
methodName
=
'runTest'
,
stride
=
[
1
],
dilation
=
2
))
...
...
@@ -161,6 +169,7 @@ def add_cases(suite):
Conv1dTestCase
(
methodName
=
'runTest'
,
padding
=
2
,
data_format
=
'NLC'
))
suite
.
addTest
(
Conv1dTestCase
(
methodName
=
'runTest'
,
padding
=
[
1
]))
suite
.
addTest
(
Conv1dTestCase
(
methodName
=
'runTest'
,
padding
=
[
1
,
2
]))
suite
.
addTest
(
Conv1dTestCase
(
methodName
=
'runTest'
,
padding
=
2
))
suite
.
addTest
(
Conv1dTestCase
(
methodName
=
'runTest'
))
suite
.
addTest
(
...
...
@@ -178,7 +187,7 @@ def add_cases(suite):
def
add_error_cases
(
suite
):
suite
.
addTest
(
Conv1dErrorTestCase
(
Conv1d
Type
ErrorTestCase
(
methodName
=
'runTest'
,
padding_mode
=
"reflect"
,
padding
=
"valid"
))
suite
.
addTest
(
Conv1dErrorTestCase
(
...
...
python/paddle/fluid/tests/unittests/test_conv1d_transpose_layer.py
浏览文件 @
96331f74
...
...
@@ -201,6 +201,7 @@ def add_cases(suite):
ConvTranspose1dTestCase
(
methodName
=
'runTest'
,
data_format
=
"NLC"
,
stride
=
3
,
output_padding
=
2
))
suite
.
addTest
(
ConvTranspose1dTestCase
(
methodName
=
'runTest'
,
padding
=
[
1
,
2
]))
def
add_error_cases
(
suite
):
...
...
python/paddle/nn/functional/conv.py
浏览文件 @
96331f74
...
...
@@ -232,7 +232,7 @@ def conv1d(x,
raise
ValueError
(
"Attr(data_format) should be 'NCL' or 'NLC'. "
"Received Attr(data_format): {}."
.
format
(
data_format
))
channel_last
=
(
data_format
==
"N
HW
C"
)
channel_last
=
(
data_format
==
"N
L
C"
)
channel_dim
=
-
1
if
channel_last
else
1
conv2d_data_format
=
"NHWC"
if
channel_last
else
"NCHW"
num_channels
=
x
.
shape
[
channel_dim
]
...
...
@@ -399,7 +399,7 @@ def conv2d(x,
`[pad_height_top, pad_height_bottom, pad_width_left, pad_width_right]`, and when
`data_format` is `"NCHW"`, `padding` can be in the form `[[0,0], [0,0],
[pad_height_top, pad_height_bottom], [pad_width_left, pad_width_right]]`.
when `data_format` is `"NHWC"`, `p
ool_p
adding` can be in the form
when `data_format` is `"NHWC"`, `padding` can be in the form
`[[0,0], [pad_height_top, pad_height_bottom], [pad_width_left, pad_width_right], [0,0]]`.
Default: padding = 0.
dilation (int|tuple): The dilation size. It means the spacing between the kernel
...
...
@@ -733,20 +733,31 @@ def conv_transpose1d(x,
stride
=
utils
.
convert_to_list
(
stride
,
1
,
'stride'
)
+
[
1
]
dilation
=
utils
.
convert_to_list
(
dilation
,
1
,
'dilation'
)
+
[
1
]
output_padding
=
utils
.
convert_to_list
(
output_padding
,
1
,
'output_padding'
)
+
[
0
]
if
output_padding
[
0
]
>
stride
[
0
]:
raise
ValueError
(
"The size of output_padding should not be greater than stride."
"But got output_padding={} and stride={}"
.
format
(
output_padding
[
0
],
stride
[
0
]))
if
output_size
is
None
:
output_size
=
[]
elif
isinstance
(
output_size
,
(
list
,
tuple
,
int
)):
output_size
=
utils
.
convert_to_list
(
output_size
,
1
,
'output_size'
)
+
[
1
]
else
:
raise
ValueError
(
"output_size should be int, or list, tuple of ints"
)
if
output_padding
!=
0
:
raise
ValueError
(
'output_padding option is mutually exclusive with '
'output_size'
)
if
isinstance
(
output_size
,
(
list
,
tuple
,
int
)):
output_size
=
utils
.
convert_to_list
(
output_size
,
1
,
'output_size'
)
+
[
1
]
else
:
raise
ValueError
(
"output_size should be int, or list, tuple of ints"
)
if
output_padding
==
0
:
output_padding
=
[]
else
:
output_padding
=
utils
.
convert_to_list
(
output_padding
,
1
,
'output_padding'
)
+
[
0
]
if
len
(
output_padding
)
>
0
and
output_padding
[
0
]
>
stride
[
0
]:
raise
ValueError
(
"The size of output_padding should not be greater than stride."
"But got output_padding={} and stride={}"
.
format
(
output_padding
[
0
],
stride
[
0
]))
op_type
=
'conv2d_transpose'
num_filters
=
weight
.
shape
[
1
]
...
...
@@ -761,16 +772,17 @@ def conv_transpose1d(x,
weight
=
nn
.
unsqueeze
(
input
=
weight
,
axes
=
[
-
1
])
if
in_dygraph_mode
():
attrs
=
(
'output_
size'
,
output_size
,
'strides'
,
stride
,
'paddings'
,
padding
,
'padding_algorithm'
,
padding_algorithm
,
'dilations
'
,
dilation
,
'groups'
,
groups
,
'use_cudnn'
,
use_cudnn
,
'data_format'
,
conv2d_data_format
)
attrs
=
(
'output_
padding'
,
output_padding
,
'output_size'
,
output_size
,
'strides'
,
stride
,
'paddings'
,
padding
,
'padding_algorithm
'
,
padding_algorithm
,
'dilations'
,
dilation
,
'groups'
,
groups
,
'
use_cudnn'
,
use_cudnn
,
'
data_format'
,
conv2d_data_format
)
out
=
getattr
(
core
.
ops
,
op_type
)(
x
,
weight
,
*
attrs
)
if
bias
is
not
None
:
out
=
nn
.
elementwise_add
(
out
,
bias
,
axis
=
channel_dim
)
else
:
inputs
=
{
'Input'
:
[
x
],
'Filter'
:
[
weight
]}
attrs
=
{
'output_padding'
:
output_padding
,
'output_size'
:
output_size
,
'strides'
:
stride
,
'paddings'
:
padding
,
...
...
@@ -791,12 +803,6 @@ def conv_transpose1d(x,
if
bias
is
not
None
:
out
=
nn
.
elementwise_add
(
out
,
bias
,
axis
=
channel_dim
)
if
output_size
is
None
:
out
=
pad2d
(
out
,
padding
=
[
0
,
output_padding
,
0
,
0
],
data_format
=
conv2d_data_format
,
name
=
name
)
out
=
nn
.
squeeze
(
input
=
out
,
axes
=
[
squeeze_axis
])
return
out
...
...
@@ -888,9 +894,9 @@ def conv_transpose2d(x,
'SAME' which is the padding algorithm. If padding size is a tuple or list,
it could be in three forms: `[pad_height, pad_width]` or
`[pad_height_top, pad_height_bottom, pad_width_left, pad_width_right]`,
and when `data_format` is `"NCHW"`, `p
ool_p
adding` can be in the form
and when `data_format` is `"NCHW"`, `padding` can be in the form
`[[0,0], [0,0], [pad_height_top, pad_height_bottom], [pad_width_left, pad_width_right]]`.
when `data_format` is `"NHWC"`, `p
ool_p
adding` can be in the form
when `data_format` is `"NHWC"`, `padding` can be in the form
`[[0,0], [pad_height_top, pad_height_bottom], [pad_width_left, pad_width_right], [0,0]]`.
Default: padding = 0.
output_padding(int|list|tuple, optional): Additional size added to one side
...
...
@@ -1116,9 +1122,9 @@ def conv3d(x,
'SAME' which is the padding algorithm. If padding size is a tuple or list,
it could be in three forms: `[pad_depth, pad_height, pad_width]` or
`[pad_depth_front, pad_depth_back, pad_height_top, pad_height_bottom, pad_width_left, pad_width_right]`,
and when `data_format` is `"NCDHW"`, `p
ool_p
adding` can be in the form
and when `data_format` is `"NCDHW"`, `padding` can be in the form
`[[0,0], [0,0], [pad_depth_front, pad_depth_back], [pad_height_top, pad_height_bottom], [pad_width_left, pad_width_right]]`.
when `data_format` is `"NDHWC"`, `p
ool_p
adding` can be in the form
when `data_format` is `"NDHWC"`, `padding` can be in the form
`[[0,0], [pad_depth_front, pad_depth_back], [pad_height_top, pad_height_bottom], [pad_width_left, pad_width_right], [0,0]]`.
Default: padding = 0.
dilation (int|tuple): The dilation size. It means the spacing between the kernel points.
...
...
@@ -1340,9 +1346,9 @@ def conv_transpose3d(x,
'SAME' which is the padding algorithm. If padding size is a tuple or list,
it could be in three forms: `[pad_depth, pad_height, pad_width]` or
`[pad_depth_front, pad_depth_back, pad_height_top, pad_height_bottom, pad_width_left, pad_width_right]`,
and when `data_format` is `"NCDHW"`, `p
ool_p
adding` can be in the form
and when `data_format` is `"NCDHW"`, `padding` can be in the form
`[[0,0], [0,0], [pad_depth_front, pad_depth_back], [pad_height_top, pad_height_bottom], [pad_width_left, pad_width_right]]`.
when `data_format` is `"NDHWC"`, `p
ool_p
adding` can be in the form
when `data_format` is `"NDHWC"`, `padding` can be in the form
`[[0,0], [pad_depth_front, pad_depth_back], [pad_height_top, pad_height_bottom], [pad_width_left, pad_width_right], [0,0]]`.
Default: padding = 0.
output_padding(int|list|tuple, optional): Additional size added to one side
...
...
python/paddle/nn/layer/conv.py
浏览文件 @
96331f74
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录