Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
66655ad8
P
Paddle
项目概览
机器未来
/
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看板
未验证
提交
66655ad8
编写于
5月 14, 2020
作者:
W
WuHaobo
提交者:
GitHub
5月 14, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test=release/1.8 cherry-pick unfold_op (#24505)
上级
ec0f78a3
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
50 addition
and
34 deletion
+50
-34
paddle/fluid/operators/unfold_op.cc
paddle/fluid/operators/unfold_op.cc
+39
-28
paddle/fluid/operators/unfold_op.h
paddle/fluid/operators/unfold_op.h
+9
-6
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+2
-0
未找到文件。
paddle/fluid/operators/unfold_op.cc
浏览文件 @
66655ad8
...
...
@@ -61,10 +61,12 @@ class UnfoldOp : public framework::OperatorWithKernel {
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X"
),
"Input(X) of UnfoldOp should not be null"
);
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"Y"
),
"Output(Y) of UnfoldOp should not be null"
);
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"X"
),
true
,
platform
::
errors
::
NotFound
(
"Input(X) of UnfoldOp should not be null"
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasOutput
(
"Y"
),
true
,
platform
::
errors
::
NotFound
(
"Output(Y) of UnfoldOp should not be null"
));
auto
in_dims
=
ctx
->
GetInputDim
(
"X"
);
std
::
vector
<
int
>
kernel_sizes
=
ctx
->
Attrs
().
Get
<
std
::
vector
<
int
>>
(
"kernel_sizes"
);
...
...
@@ -74,31 +76,36 @@ class UnfoldOp : public framework::OperatorWithKernel {
ctx
->
Attrs
().
Get
<
std
::
vector
<
int
>>
(
"dilations"
);
// Only [N, C, H, W] input supported now
PADDLE_ENFORCE
(
in_dims
.
size
()
==
4
,
"Input should be 4-D tensor of format [N, C, H, W], but get %u"
,
in_dims
.
size
());
PADDLE_ENFORCE
(
in_dims
.
size
()
-
kernel_sizes
.
size
()
==
2U
,
"The dims of X should be larger than that of kernel_sizes "
"by a number of 2, due to the batch size and input channel dim. "
"But recieved dims(X:%u) - dims(kernel_sizes:%u) != 2"
,
in_dims
.
size
(),
kernel_sizes
.
size
());
PADDLE_ENFORCE_EQ
(
in_dims
.
size
(),
4
,
platform
::
errors
::
InvalidArgument
(
"Input should be 4-D tensor of format [N, C, H, W], but get %u"
,
in_dims
.
size
()));
PADDLE_ENFORCE_EQ
(
in_dims
.
size
()
-
kernel_sizes
.
size
(),
2U
,
platform
::
errors
::
InvalidArgument
(
"The dims of X should be larger than that of kernel_sizes "
"by a number of 2, due to the batch size and input channel dim. "
"But recieved dims(X:%u) - dims(kernel_sizes:%u) != 2"
,
in_dims
.
size
(),
kernel_sizes
.
size
()));
PADDLE_ENFORCE_EQ
(
strides
.
size
(),
kernel_sizes
.
size
(),
"The dims of strides should be the same with that of kernel_sizes. "
"But recieved dims(strides: %u) != dims(kernel_sizes: %u)."
,
strides
.
size
(),
kernel_sizes
.
size
());
platform
::
errors
::
InvalidArgument
(
"The dims of strides should be the same with that of kernel_sizes. "
"But recieved dims(strides: %u) != dims(kernel_sizes: %u)."
,
strides
.
size
(),
kernel_sizes
.
size
()));
PADDLE_ENFORCE_EQ
(
paddings
.
size
(),
2
*
strides
.
size
(),
"The dims of paddings should be 2 times of that of strides. "
"But recieved dims(paddings: %u) != 2*dims(strides: %u)."
,
paddings
.
size
(),
strides
.
size
());
platform
::
errors
::
InvalidArgument
(
"The dims of paddings should be 2 times of that of strides. "
"But recieved dims(paddings: %u) != 2*dims(strides: %u)."
,
paddings
.
size
(),
strides
.
size
()));
PADDLE_ENFORCE_EQ
(
strides
.
size
(),
dilations
.
size
(),
"The dims of strides should be the same with that of dilations. "
"But recieved dims(strides: %u) != dims(dilations: %u)."
,
strides
.
size
(),
dilations
.
size
());
platform
::
errors
::
InvalidArgument
(
"The dims of strides should be the same with that of dilations. "
"But recieved dims(strides: %u) != dims(dilations: %u)."
,
strides
.
size
(),
dilations
.
size
()));
std
::
vector
<
int
>
out_dims
;
out_dims
.
push_back
(
in_dims
[
0
]);
...
...
@@ -131,11 +138,15 @@ class UnfoldGradOp : public framework::OperatorWithKernel {
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE
(
ctx
->
HasInput
(
framework
::
GradVarName
(
"Y"
)),
"The gradient of Y should not be null"
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X"
),
"The input X should not be null"
);
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
framework
::
GradVarName
(
"X"
)),
"The gradient of X should not be null"
);
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
framework
::
GradVarName
(
"Y"
)),
true
,
platform
::
errors
::
NotFound
(
"The gradient of Y should not be null"
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"X"
),
true
,
platform
::
errors
::
NotFound
(
"The input X should not be null"
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasOutput
(
framework
::
GradVarName
(
"X"
)),
true
,
platform
::
errors
::
NotFound
(
"The gradient of X should not be null"
));
ctx
->
SetOutputDim
(
framework
::
GradVarName
(
"X"
),
ctx
->
GetInputDim
(
"X"
));
}
...
...
paddle/fluid/operators/unfold_op.h
浏览文件 @
66655ad8
...
...
@@ -29,12 +29,15 @@ inline int CalcOutputSize(int input_size, int filter_size, int dilation,
int
padding1
,
int
padding2
,
int
stride
)
{
const
int
dkernel
=
dilation
*
(
filter_size
-
1
)
+
1
;
int
output_size
=
(
input_size
+
padding1
+
padding2
-
dkernel
)
/
stride
+
1
;
PADDLE_ENFORCE
(
output_size
>
0
,
"Due to the settings of padding(%d, %d), filter_size(%d), "
"dilation(%d) and "
"stride(%d), the output size is less than 0, please check "
"again. Input_size:%d"
,
padding1
,
padding2
,
filter_size
,
dilation
,
stride
,
input_size
);
PADDLE_ENFORCE_GT
(
output_size
,
0UL
,
platform
::
errors
::
InvalidArgument
(
"Due to the settings of padding(%d, %d), filter_size(%d), "
"dilation(%d) and "
"stride(%d), the output size is less than 0, please check "
"again. Input_size:%d"
,
padding1
,
padding2
,
filter_size
,
dilation
,
stride
,
input_size
));
return
output_size
;
}
...
...
python/paddle/fluid/layers/nn.py
浏览文件 @
66655ad8
...
...
@@ -15257,6 +15257,8 @@ def unfold(x, kernel_sizes, strides=1, paddings=0, dilations=1, name=None):
helper = LayerHelper("unfold", **locals())
check_variable_and_dtype(x, 'x', ['float32', 'float64'], 'unfold')
assert len(x.shape) == 4, \
"input should be the format of [N, C, H, W]"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录