Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
eb019760
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
eb019760
编写于
9月 08, 2020
作者:
W
whs
提交者:
GitHub
9月 08, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[2.0 API]Add checker in grid_sample_grad op (#27126)
上级
a28ae86e
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
16 addition
and
12 deletion
+16
-12
paddle/fluid/operators/grid_sampler_op.cc
paddle/fluid/operators/grid_sampler_op.cc
+5
-1
paddle/fluid/operators/grid_sampler_op.cu
paddle/fluid/operators/grid_sampler_op.cu
+2
-2
paddle/fluid/operators/grid_sampler_op.h
paddle/fluid/operators/grid_sampler_op.h
+2
-2
python/paddle/fluid/tests/unittests/test_grid_sample_function.py
...paddle/fluid/tests/unittests/test_grid_sample_function.py
+1
-1
python/paddle/fluid/tests/unittests/test_grid_sampler_op.py
python/paddle/fluid/tests/unittests/test_grid_sampler_op.py
+4
-4
python/paddle/nn/functional/vision.py
python/paddle/nn/functional/vision.py
+2
-2
未找到文件。
paddle/fluid/operators/grid_sampler_op.cc
浏览文件 @
eb019760
...
...
@@ -115,7 +115,7 @@ class GridSampleOpMaker : public framework::OpProtoAndCheckerMaker {
AddAttr
<
std
::
string
>
(
"padding_mode"
,
"(bool, default true) The padding method used when source"
"index is out of input images. It can be 'zeros', 'reflect' and "
"index is out of input images. It can be 'zeros', 'reflect
ion
' and "
"'border'."
)
.
SetDefault
(
"zeros"
);
...
...
@@ -174,6 +174,10 @@ 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"
);
OP_INOUT_CHECK
(
ctx
->
HasOutput
(
framework
::
GradVarName
(
"Grid"
)),
"Output"
,
framework
::
GradVarName
(
"Grid"
),
"grid_sampler"
);
auto
input_dims
=
ctx
->
GetInputDim
(
"X"
);
auto
grid_dims
=
ctx
->
GetInputDim
(
"Grid"
);
if
(
ctx
->
HasOutput
(
framework
::
GradVarName
(
"X"
)))
{
...
...
paddle/fluid/operators/grid_sampler_op.cu
浏览文件 @
eb019760
...
...
@@ -268,7 +268,7 @@ class GridSampleOpCUDAKernel : public framework::OpKernel<T> {
Mode
mode
;
if
(
padding_mode_s
==
"border"
)
{
padding_mode
=
PaddingMode
::
border
;
}
else
if
(
padding_mode_s
==
"reflect"
)
{
}
else
if
(
padding_mode_s
==
"reflect
ion
"
)
{
padding_mode
=
PaddingMode
::
reflect
;
}
else
{
padding_mode
=
PaddingMode
::
zeros
;
...
...
@@ -432,7 +432,7 @@ class GridSampleGradOpCUDAKernel : public framework::OpKernel<T> {
Mode
mode
;
if
(
padding_mode_s
==
"border"
)
{
padding_mode
=
PaddingMode
::
border
;
}
else
if
(
padding_mode_s
==
"reflect"
)
{
}
else
if
(
padding_mode_s
==
"reflect
ion
"
)
{
padding_mode
=
PaddingMode
::
reflect
;
}
else
{
padding_mode
=
PaddingMode
::
zeros
;
...
...
paddle/fluid/operators/grid_sampler_op.h
浏览文件 @
eb019760
...
...
@@ -76,7 +76,7 @@ static inline void clip(const platform::CPUDeviceContext& ctx,
if
(
padding_mode
==
"border"
)
{
grid_slice_t
.
device
(
place
)
=
grid_slice_t
.
cwiseMax
(
static_cast
<
T
>
(
0
))
.
cwiseMin
(
static_cast
<
T
>
(
max_val
));
}
else
if
(
padding_mode
==
"reflect"
)
{
}
else
if
(
padding_mode
==
"reflect
ion
"
)
{
if
(
align_corners
)
{
auto
double_range
=
static_cast
<
T
>
(
max_val
*
2
);
auto
grid_abs
=
grid_slice_t
.
abs
();
...
...
@@ -117,7 +117,7 @@ static inline void clipWithMask(const platform::CPUDeviceContext& ctx,
auto
in_bound
=
(
res
==
grid_slice_t
);
grid_scale_t
.
device
(
place
)
=
grid_scale_t
*
in_bound
.
template
cast
<
T
>();
grid_slice_t
.
device
(
place
)
=
res
;
}
else
if
(
padding_mode
==
"reflect"
)
{
}
else
if
(
padding_mode
==
"reflect
ion
"
)
{
if
(
align_corners
)
{
auto
double_range
=
static_cast
<
T
>
(
max_val
*
2
);
auto
is_neg
=
(
grid_slice_t
<
static_cast
<
T
>
(
0
));
...
...
python/paddle/fluid/tests/unittests/test_grid_sample_function.py
浏览文件 @
eb019760
...
...
@@ -100,7 +100,7 @@ def add_cases(suite):
GridSampleTestCase
(
methodName
=
'runTest'
,
mode
=
'bilinear'
,
padding_mode
=
'reflect'
,
padding_mode
=
'reflect
ion
'
,
align_corners
=
True
))
suite
.
addTest
(
GridSampleTestCase
(
...
...
python/paddle/fluid/tests/unittests/test_grid_sampler_op.py
浏览文件 @
eb019760
...
...
@@ -73,7 +73,7 @@ def unnormalizeAndClip(grid_slice, max_val, align_corners, padding_mode):
if
padding_mode
==
"border"
:
grid_slice
=
clip
(
grid_slice
,
0
,
max_val
)
elif
padding_mode
==
"reflect"
:
elif
padding_mode
==
"reflect
ion
"
:
double_range
=
2
*
max_val
if
align_corners
else
(
max_val
+
1
)
*
2
grid_abs
=
np
.
abs
(
grid_slice
)
if
align_corners
else
np
.
abs
(
grid_slice
+
0.5
)
...
...
@@ -211,7 +211,7 @@ class Case2(TestGridSamplerOp):
self
.
grid_shape
=
(
2
,
8
,
9
,
2
)
self
.
theta_shape
=
(
2
,
2
,
3
)
self
.
align_corners
=
False
self
.
padding_mode
=
"reflect"
self
.
padding_mode
=
"reflect
ion
"
self
.
mode
=
"bilinear"
...
...
@@ -221,7 +221,7 @@ class Case3(TestGridSamplerOp):
self
.
grid_shape
=
(
2
,
8
,
9
,
2
)
self
.
theta_shape
=
(
2
,
2
,
3
)
self
.
align_corners
=
True
self
.
padding_mode
=
"reflect"
self
.
padding_mode
=
"reflect
ion
"
self
.
mode
=
"bilinear"
...
...
@@ -231,7 +231,7 @@ class Case4(TestGridSamplerOp):
self
.
grid_shape
=
(
2
,
8
,
9
,
2
)
self
.
theta_shape
=
(
2
,
2
,
3
)
self
.
align_corners
=
False
self
.
padding_mode
=
"reflect"
self
.
padding_mode
=
"reflect
ion
"
self
.
mode
=
"nearest"
self
.
numeric_grad_delta
=
0.0001
...
...
python/paddle/nn/functional/vision.py
浏览文件 @
eb019760
...
...
@@ -249,7 +249,7 @@ def grid_sample(x,
mode(str, optional): The interpolation method which can be 'bilinear' or 'nearest'.
Default: 'bilinear'.
padding_mode(str, optional) The padding method used when source index
is out of input images. It can be 'zeros', 'reflect' and 'border'.
is out of input images. It can be 'zeros', 'reflect
ion
' and 'border'.
Default: zeros.
align_corners(bool, optional): If `align_corners` is true, it will projects
-1 and 1 to the centers of the corner pixels. Otherwise, it will
...
...
@@ -312,7 +312,7 @@ def grid_sample(x,
if
not
isinstance
(
grid
,
Variable
):
raise
ValueError
(
"The grid should be a Variable"
)
_modes
=
[
'bilinear'
,
'nearest'
]
_padding_modes
=
[
'zeros'
,
'reflect'
,
'border'
]
_padding_modes
=
[
'zeros'
,
'reflect
ion
'
,
'border'
]
if
mode
not
in
_modes
:
raise
ValueError
(
"The mode of grid sample function should be in {}, but got: {}"
.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录