Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
c2f5a3ad
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看板
未验证
提交
c2f5a3ad
编写于
4月 10, 2020
作者:
W
wangguanzhong
提交者:
GitHub
4月 10, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enhance the error message of roi_align, test=develop (#23649)
上级
cec234b1
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
61 addition
and
23 deletion
+61
-23
paddle/fluid/operators/roi_align_op.cc
paddle/fluid/operators/roi_align_op.cc
+48
-21
paddle/fluid/operators/roi_align_op.cu
paddle/fluid/operators/roi_align_op.cu
+5
-1
paddle/fluid/operators/roi_align_op.h
paddle/fluid/operators/roi_align_op.h
+5
-1
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+3
-0
未找到文件。
paddle/fluid/operators/roi_align_op.cc
浏览文件 @
c2f5a3ad
...
...
@@ -23,35 +23,59 @@ class ROIAlignOp : public framework::OperatorWithKernel {
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X"
),
"Input(X) of ROIAlignOp should not be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"ROIs"
),
"Input(ROIs) of ROIAlignOp should not be null."
);
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"Out"
),
"Output(Out) of ROIAlignOp should not be null."
);
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"X"
),
true
,
platform
::
errors
::
NotFound
(
"Input(X) of ROIAlignOp "
"is not found."
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"ROIs"
),
true
,
platform
::
errors
::
NotFound
(
"Input(ROIs) of ROIAlignOp "
"is not found."
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasOutput
(
"Out"
),
true
,
platform
::
errors
::
NotFound
(
"Output(Out) of ROIAlignOp "
"is not found."
));
auto
input_dims
=
ctx
->
GetInputDim
(
"X"
);
auto
rois_dims
=
ctx
->
GetInputDim
(
"ROIs"
);
PADDLE_ENFORCE
(
input_dims
.
size
()
==
4
,
"The format of input tensor is NCHW."
);
PADDLE_ENFORCE
(
rois_dims
.
size
()
==
2
,
"ROIs should be a 2-D LoDTensor of shape (num_rois, 4)"
"given as [[x1, y1, x2, y2], ...]."
);
PADDLE_ENFORCE_EQ
(
input_dims
.
size
(),
4
,
platform
::
errors
::
InvalidArgument
(
"The format of Input(X) in"
"RoIAlignOp is NCHW. And the rank of input must be 4. "
"But received rank = %d"
,
input_dims
.
size
()));
PADDLE_ENFORCE_EQ
(
rois_dims
.
size
(),
2
,
platform
::
errors
::
InvalidArgument
(
"The rank of Input(ROIs) "
"in RoIAlignOp should be 2. "
"But the rank of RoIs is %d"
,
rois_dims
.
size
()));
if
(
ctx
->
IsRuntime
())
{
PADDLE_ENFORCE
(
rois_dims
[
1
]
==
4
,
"ROIs should be a 2-D LoDTensor of shape (num_rois, 4)"
"given as [[x1, y1, x2, y2], ...]."
);
PADDLE_ENFORCE_EQ
(
rois_dims
[
1
],
4
,
platform
::
errors
::
InvalidArgument
(
"The second dimension "
"of Input(ROIs) should be 4. But received the "
"dimension = %d"
,
rois_dims
[
1
]));
}
int
pooled_height
=
ctx
->
Attrs
().
Get
<
int
>
(
"pooled_height"
);
int
pooled_width
=
ctx
->
Attrs
().
Get
<
int
>
(
"pooled_width"
);
float
spatial_scale
=
ctx
->
Attrs
().
Get
<
float
>
(
"spatial_scale"
);
PADDLE_ENFORCE_GT
(
pooled_height
,
0
,
"The pooled output height must greater than 0"
);
platform
::
errors
::
InvalidArgument
(
"The pooled output "
"height must greater than 0. But received "
"pooled_height = %d"
,
pooled_height
));
PADDLE_ENFORCE_GT
(
pooled_width
,
0
,
"The pooled output width must greater than 0"
);
platform
::
errors
::
InvalidArgument
(
"The pooled output "
"width must greater than 0. But received "
"pooled_width = %d"
,
pooled_width
));
PADDLE_ENFORCE_GT
(
spatial_scale
,
0.0
f
,
"The spatial scale must greater than 0"
);
platform
::
errors
::
InvalidArgument
(
"The spatial scale "
"must greater than 0 But received spatial_scale = %f"
,
spatial_scale
));
auto
out_dims
=
input_dims
;
out_dims
[
0
]
=
rois_dims
[
0
];
...
...
@@ -76,10 +100,13 @@ class ROIAlignGradOp : public framework::OperatorWithKernel {
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE
(
ctx
->
HasInput
(
framework
::
GradVarName
(
"Out"
)),
"The GRAD@Out of ROIAlignGradOp should not be null."
);
PADDLE_ENFORCE
(
ctx
->
HasOutputs
(
framework
::
GradVarName
(
"X"
)),
"The GRAD@X of ROIAlignGradOp should not be null."
);
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
framework
::
GradVarName
(
"Out"
)),
true
,
platform
::
errors
::
NotFound
(
"The GRAD@Out of ROIAlignGradOp "
"is not found."
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasOutputs
(
framework
::
GradVarName
(
"X"
)),
true
,
platform
::
errors
::
NotFound
(
"The GRAD@X of ROIAlignGradOp "
"is not found."
));
ctx
->
SetOutputsDim
(
framework
::
GradVarName
(
"X"
),
ctx
->
GetInputsDim
(
"X"
));
}
...
...
paddle/fluid/operators/roi_align_op.cu
浏览文件 @
c2f5a3ad
...
...
@@ -266,7 +266,11 @@ class GPUROIAlignOpKernel : public framework::OpKernel<T> {
int
rois_batch_size
=
rois_lod
.
size
()
-
1
;
PADDLE_ENFORCE_EQ
(
rois_batch_size
,
batch_size
,
"The rois_batch_size and imgs batch_size must be the same."
);
platform
::
errors
::
InvalidArgument
(
"The rois_batch_size and imgs "
"batch_size must be the same. But received rois_batch_size = %d, "
"batch_size = %d"
,
rois_batch_size
,
batch_size
));
int
rois_num_with_lod
=
rois_lod
[
rois_batch_size
];
PADDLE_ENFORCE_EQ
(
rois_num
,
rois_num_with_lod
,
"The rois_num from input and lod must be the same."
);
...
...
paddle/fluid/operators/roi_align_op.h
浏览文件 @
c2f5a3ad
...
...
@@ -172,7 +172,11 @@ class CPUROIAlignOpKernel : public framework::OpKernel<T> {
int
rois_batch_size
=
rois_lod
.
size
()
-
1
;
PADDLE_ENFORCE_EQ
(
rois_batch_size
,
batch_size
,
"The rois_batch_size and imgs batch_size must be the same."
);
platform
::
errors
::
InvalidArgument
(
"The rois_batch_size and imgs "
"batch_size must be the same. But received rois_batch_size = %d, "
"batch_size = %d"
,
rois_batch_size
,
batch_size
));
int
rois_num_with_lod
=
rois_lod
[
rois_batch_size
];
PADDLE_ENFORCE_EQ
(
rois_num
,
rois_num_with_lod
,
"The rois_num from input and lod must be the same."
);
...
...
python/paddle/fluid/layers/nn.py
浏览文件 @
c2f5a3ad
...
...
@@ -6723,6 +6723,9 @@ def roi_align(input,
spatial_scale=0.5,
sampling_ratio=-1)
"""
check_variable_and_dtype(input, 'input', ['float32', 'float64'],
'roi_align')
check_variable_and_dtype(rois, 'rois', ['float32', 'float64'], 'roi_align')
helper = LayerHelper('roi_align', **locals())
dtype = helper.input_dtype()
align_out = helper.create_variable_for_type_inference(dtype)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录