Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
b1b24463
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看板
未验证
提交
b1b24463
编写于
3月 17, 2022
作者:
C
Chen Weihang
提交者:
GitHub
3月 17, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
move grid sample op infershape (#40625)
上级
827b6a0e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
59 addition
and
51 deletion
+59
-51
paddle/fluid/operators/grid_sampler_op.cc
paddle/fluid/operators/grid_sampler_op.cc
+12
-51
paddle/phi/infermeta/binary.cc
paddle/phi/infermeta/binary.cc
+42
-0
paddle/phi/infermeta/binary.h
paddle/phi/infermeta/binary.h
+5
-0
未找到文件。
paddle/fluid/operators/grid_sampler_op.cc
浏览文件 @
b1b24463
...
...
@@ -15,9 +15,13 @@ limitations under the License. */
#include <memory>
#include <string>
#include "paddle/fluid/framework/infershape_utils.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/framework/op_version_registry.h"
#include "paddle/fluid/platform/device/gpu/gpu_dnn.h"
#include "paddle/phi/core/infermeta_utils.h"
#include "paddle/phi/infermeta/backward.h"
#include "paddle/phi/infermeta/binary.h"
namespace
paddle
{
namespace
operators
{
...
...
@@ -27,43 +31,6 @@ using Tensor = framework::Tensor;
class
GridSampleOp
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
OP_INOUT_CHECK
(
ctx
->
HasInput
(
"X"
),
"Input"
,
"X"
,
"GridSampler"
);
OP_INOUT_CHECK
(
ctx
->
HasInput
(
"Grid"
),
"Input"
,
"Grid"
,
"GridSampler"
);
OP_INOUT_CHECK
(
ctx
->
HasOutput
(
"Output"
),
"Output"
,
"Output"
,
"GridSampler"
);
auto
x_dims
=
ctx
->
GetInputDim
(
"X"
);
auto
grid_dims
=
ctx
->
GetInputDim
(
"Grid"
);
PADDLE_ENFORCE_EQ
(
x_dims
.
size
(),
4
,
platform
::
errors
::
InvalidArgument
(
"Input(X) of GridSampleOp should be 4-D Tensor, but "
"received X dimension size(%d)"
,
x_dims
.
size
()));
PADDLE_ENFORCE_EQ
(
grid_dims
.
size
(),
4
,
platform
::
errors
::
InvalidArgument
(
"Input(Grid) of GridSampleOp should be 4-D Tensor, "
"but received X dimension size(%d)"
,
grid_dims
.
size
()));
if
(
ctx
->
IsRuntime
()
||
grid_dims
[
3
]
>
0
)
{
PADDLE_ENFORCE_EQ
(
grid_dims
[
3
],
2
,
platform
::
errors
::
InvalidArgument
(
"Input(Grid) dimension[3] should be 2, but received %d"
,
grid_dims
[
3
]));
}
if
(
ctx
->
IsRuntime
())
{
PADDLE_ENFORCE_EQ
(
grid_dims
[
0
],
x_dims
[
0
],
platform
::
errors
::
InvalidArgument
(
"Input(X) and Input(Grid) dimension[0] should be equal, but "
"received X dimension[0](%d) != Grid dimension[0](%d)"
,
x_dims
[
0
],
grid_dims
[
0
]));
}
ctx
->
SetOutputDim
(
"Output"
,
{
x_dims
[
0
],
x_dims
[
1
],
grid_dims
[
1
],
grid_dims
[
2
]});
ctx
->
ShareLoD
(
"X"
,
"Output"
);
}
protected:
framework
::
OpKernelType
GetExpectedKernelType
(
...
...
@@ -173,18 +140,6 @@ class GridSampleOpMaker : public framework::OpProtoAndCheckerMaker {
class
GridSampleOpGrad
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
OP_INOUT_CHECK
(
ctx
->
HasOutput
(
framework
::
GradVarName
(
"X"
)),
"Output"
,
framework
::
GradVarName
(
"X"
),
"grid_sampler"
);
auto
input_dims
=
ctx
->
GetInputDim
(
"X"
);
auto
grid_dims
=
ctx
->
GetInputDim
(
"Grid"
);
if
(
ctx
->
HasOutput
(
framework
::
GradVarName
(
"X"
)))
{
ctx
->
SetOutputDim
(
framework
::
GradVarName
(
"X"
),
input_dims
);
}
if
(
ctx
->
HasOutput
(
framework
::
GradVarName
(
"Grid"
)))
{
ctx
->
SetOutputDim
(
framework
::
GradVarName
(
"Grid"
),
grid_dims
);
}
}
protected:
framework
::
OpKernelType
GetExpectedKernelType
(
...
...
@@ -224,10 +179,16 @@ class GridSampleGradMaker : public framework::SingleGradOpMaker<T> {
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
DECLARE_INFER_SHAPE_FUNCTOR
(
grid_sampler
,
GridSamplerInferShapeFunctor
,
PD_INFER_META
(
phi
::
GridSampleBaseInferMeta
));
REGISTER_OPERATOR
(
grid_sampler
,
ops
::
GridSampleOp
,
ops
::
GridSampleOpMaker
,
ops
::
GridSampleGradMaker
<
paddle
::
framework
::
OpDesc
>
,
ops
::
GridSampleGradMaker
<
paddle
::
imperative
::
OpBase
>
);
REGISTER_OPERATOR
(
grid_sampler_grad
,
ops
::
GridSampleOpGrad
);
ops
::
GridSampleGradMaker
<
paddle
::
imperative
::
OpBase
>
,
GridSamplerInferShapeFunctor
);
DECLARE_INFER_SHAPE_FUNCTOR
(
grid_sampler_grad
,
GridSamplerGradInferShapeFunctor
,
PD_INFER_META
(
phi
::
GeneralBinaryGradInferMeta
));
REGISTER_OPERATOR
(
grid_sampler_grad
,
ops
::
GridSampleOpGrad
,
GridSamplerGradInferShapeFunctor
);
REGISTER_OP_VERSION
(
grid_sampler
)
.
AddCheckpoint
(
...
...
paddle/phi/infermeta/binary.cc
浏览文件 @
b1b24463
...
...
@@ -571,6 +571,48 @@ void GatherTreeMeta(const MetaTensor& ids,
out
->
set_dims
(
ids_dims
);
}
void
GridSampleBaseInferMeta
(
const
MetaTensor
&
x
,
const
MetaTensor
&
grid
,
MetaTensor
*
out
,
MetaConfig
config
)
{
auto
x_dims
=
x
.
dims
();
auto
grid_dims
=
grid
.
dims
();
PADDLE_ENFORCE_EQ
(
x_dims
.
size
(),
4
,
phi
::
errors
::
InvalidArgument
(
"Input(X) of GridSampleOp should be 4-D Tensor, but "
"received X dimension size(%d)"
,
x_dims
.
size
()));
PADDLE_ENFORCE_EQ
(
grid_dims
.
size
(),
4
,
phi
::
errors
::
InvalidArgument
(
"Input(Grid) of GridSampleOp should be 4-D Tensor, "
"but received X dimension size(%d)"
,
grid_dims
.
size
()));
if
(
config
.
is_runtime
||
grid_dims
[
3
]
>
0
)
{
PADDLE_ENFORCE_EQ
(
grid_dims
[
3
],
2
,
phi
::
errors
::
InvalidArgument
(
"Input(Grid) dimension[3] should be 2, but received %d"
,
grid_dims
[
3
]));
}
if
(
config
.
is_runtime
)
{
PADDLE_ENFORCE_EQ
(
grid_dims
[
0
],
x_dims
[
0
],
phi
::
errors
::
InvalidArgument
(
"Input(X) and Input(Grid) dimension[0] should be equal, but "
"received X dimension[0](%d) != Grid dimension[0](%d)"
,
x_dims
[
0
],
grid_dims
[
0
]));
}
out
->
set_dims
({
x_dims
[
0
],
x_dims
[
1
],
grid_dims
[
1
],
grid_dims
[
2
]});
out
->
set_dtype
(
x
.
dtype
());
out
->
share_lod
(
x
);
}
void
HuberLossInferMeta
(
const
MetaTensor
&
input
,
const
MetaTensor
&
label
,
float
delta
,
...
...
paddle/phi/infermeta/binary.h
浏览文件 @
b1b24463
...
...
@@ -103,6 +103,11 @@ void GatherTreeMeta(const MetaTensor& ids,
const
MetaTensor
&
parents
,
MetaTensor
*
out
);
void
GridSampleBaseInferMeta
(
const
MetaTensor
&
x
,
const
MetaTensor
&
grid
,
MetaTensor
*
out
,
MetaConfig
config
=
MetaConfig
());
void
HuberLossInferMeta
(
const
MetaTensor
&
input_meta
,
const
MetaTensor
&
label_meta
,
float
delta
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录