Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
52a6ca0c
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
52a6ca0c
编写于
8月 28, 2020
作者:
L
littletomatodonkey
提交者:
GitHub
8月 28, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test=develop, improve pad assertion error (#26748)
上级
c03092b1
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
57 addition
and
2 deletion
+57
-2
python/paddle/fluid/tests/unittests/test_pad3d_op.py
python/paddle/fluid/tests/unittests/test_pad3d_op.py
+44
-1
python/paddle/nn/functional/common.py
python/paddle/nn/functional/common.py
+13
-1
未找到文件。
python/paddle/fluid/tests/unittests/test_pad3d_op.py
浏览文件 @
52a6ca0c
...
...
@@ -166,7 +166,11 @@ class TestPadAPI(unittest.TestCase):
value
=
100
input_data
=
np
.
random
.
rand
(
*
input_shape
).
astype
(
np
.
float32
)
x
=
paddle
.
data
(
name
=
"x"
,
shape
=
input_shape
)
result
=
F
.
pad
(
x
=
x
,
pad
=
pad
,
value
=
value
,
mode
=
mode
)
result
=
F
.
pad
(
x
=
x
,
pad
=
pad
,
value
=
value
,
mode
=
mode
,
data_format
=
"NCDHW"
)
exe
=
Executor
(
place
)
fetches
=
exe
.
run
(
default_main_program
(),
feed
=
{
"x"
:
input_data
},
...
...
@@ -666,5 +670,44 @@ class TestPad3dOpError(unittest.TestCase):
self
.
assertRaises
(
Exception
,
test_reflect_3
)
class
TestPadDataformatError
(
unittest
.
TestCase
):
def
test_errors
(
self
):
def
test_ncl
():
paddle
.
disable_static
(
paddle
.
CPUPlace
())
input_shape
=
(
1
,
2
,
3
,
4
)
pad
=
paddle
.
to_tensor
(
np
.
array
([
2
,
1
,
2
,
1
]).
astype
(
'int32'
))
data
=
np
.
arange
(
np
.
prod
(
input_shape
),
dtype
=
np
.
float64
).
reshape
(
input_shape
)
+
1
my_pad
=
nn
.
ReplicationPad1d
(
padding
=
pad
,
data_format
=
"NCL"
)
data
=
paddle
.
to_tensor
(
data
)
result
=
my_pad
(
data
)
def
test_nchw
():
paddle
.
disable_static
(
paddle
.
CPUPlace
())
input_shape
=
(
1
,
2
,
4
)
pad
=
paddle
.
to_tensor
(
np
.
array
([
2
,
1
,
2
,
1
]).
astype
(
'int32'
))
data
=
np
.
arange
(
np
.
prod
(
input_shape
),
dtype
=
np
.
float64
).
reshape
(
input_shape
)
+
1
my_pad
=
nn
.
ReplicationPad1d
(
padding
=
pad
,
data_format
=
"NCHW"
)
data
=
paddle
.
to_tensor
(
data
)
result
=
my_pad
(
data
)
def
test_ncdhw
():
paddle
.
disable_static
(
paddle
.
CPUPlace
())
input_shape
=
(
1
,
2
,
3
,
4
)
pad
=
paddle
.
to_tensor
(
np
.
array
([
2
,
1
,
2
,
1
]).
astype
(
'int32'
))
data
=
np
.
arange
(
np
.
prod
(
input_shape
),
dtype
=
np
.
float64
).
reshape
(
input_shape
)
+
1
my_pad
=
nn
.
ReplicationPad1d
(
padding
=
pad
,
data_format
=
"NCDHW"
)
data
=
paddle
.
to_tensor
(
data
)
result
=
my_pad
(
data
)
self
.
assertRaises
(
AssertionError
,
test_ncl
)
self
.
assertRaises
(
AssertionError
,
test_nchw
)
self
.
assertRaises
(
AssertionError
,
test_ncdhw
)
if
__name__
==
'__main__'
:
unittest
.
main
()
python/paddle/nn/functional/common.py
浏览文件 @
52a6ca0c
...
...
@@ -1230,7 +1230,19 @@ def pad(x, pad, mode='constant', value=0, data_format="NCHW", name=None):
x_dim
=
len
(
x
.
shape
)
original_data_format
=
data_format
assert
x_dim
in
[
3
,
4
,
5
],
"input tesor dimension must be in [3, 4, 5] but got {}"
.
format
(
x_dim
)
supported_format_map
=
{
3
:
[
"NCL"
,
"NLC"
],
4
:
[
"NCHW"
,
"NHWC"
],
5
:
[
"NCDHW"
,
"NDHWC"
],
}
assert
data_format
in
supported_format_map
[
x_dim
],
\
"input tensor dimension is {}, it's data format should be in {} but got {}"
.
format
(
x_dim
,
supported_format_map
[
x_dim
],
data_format
)
unsqueezed_dim
=
[]
if
isinstance
(
pad
,
Variable
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录