Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
5fc42753
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看板
未验证
提交
5fc42753
编写于
6月 05, 2020
作者:
W
whs
提交者:
GitHub
6月 05, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Enhance checking in some operator. (#24935)
上级
b8eb52f6
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
269 addition
and
113 deletion
+269
-113
paddle/fluid/operators/affine_grid_op.cc
paddle/fluid/operators/affine_grid_op.cc
+43
-15
paddle/fluid/operators/detection/generate_proposal_labels_op.cc
.../fluid/operators/detection/generate_proposal_labels_op.cc
+72
-35
paddle/fluid/operators/detection/generate_proposals_op.cc
paddle/fluid/operators/detection/generate_proposals_op.cc
+15
-9
paddle/fluid/operators/detection/generate_proposals_op.cu
paddle/fluid/operators/detection/generate_proposals_op.cu
+5
-1
paddle/fluid/operators/detection/rpn_target_assign_op.cc
paddle/fluid/operators/detection/rpn_target_assign_op.cc
+53
-31
paddle/fluid/operators/im2sequence_op.cc
paddle/fluid/operators/im2sequence_op.cc
+19
-9
paddle/fluid/operators/label_smooth_op.cc
paddle/fluid/operators/label_smooth_op.cc
+14
-8
python/paddle/fluid/layers/detection.py
python/paddle/fluid/layers/detection.py
+35
-1
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+12
-2
python/paddle/fluid/tests/unittests/test_layers.py
python/paddle/fluid/tests/unittests/test_layers.py
+1
-2
未找到文件。
paddle/fluid/operators/affine_grid_op.cc
浏览文件 @
5fc42753
...
...
@@ -42,29 +42,57 @@ class AffineGridOp : public framework::OperatorWithKernel {
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"Theta"
),
"Input(Theta) of AffineGridOp should not be null."
);
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"Output"
),
"Output(Output) of AffineGridOp should not be null."
);
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"Theta"
),
true
,
platform
::
errors
::
NotFound
(
"The input 'Theta' of AffineGridOp is not found."
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasOutput
(
"Output"
),
true
,
platform
::
errors
::
NotFound
(
"The output 'Output' of AffineGridOp is not found."
));
auto
theta_dims
=
ctx
->
GetInputDim
(
"Theta"
);
PADDLE_ENFORCE
(
theta_dims
.
size
()
==
3
,
"AffineGrid's Input(Theta) should be 3-D tensor."
);
PADDLE_ENFORCE_EQ
(
theta_dims
.
size
(),
3
,
platform
::
errors
::
InvalidArgument
(
"The input Theta's dimensions size should be 3. But received "
"Theta's demensions size=[%d], Theta's dimensions=[%s]."
,
theta_dims
.
size
(),
theta_dims
));
auto
output_shape
=
ctx
->
Attrs
().
Get
<
std
::
vector
<
int
>>
(
"output_shape"
);
if
(
output_shape
.
size
()
==
0
)
{
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"OutputShape"
),
"Input(OutputShape) of AffineGridOp should not be null if "
"attr(output_shape) is not configured."
);
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"OutputShape"
),
true
,
platform
::
errors
::
NotFound
(
"The input 'OutputShape' of AffineGridOp should not be null if "
"'output_shape' is not configured."
));
auto
output_shape_dims
=
ctx
->
GetInputDim
(
"OutputShape"
);
PADDLE_ENFORCE
(
output_shape_dims
.
size
()
==
1
,
"AffineGrid's Input(OutputShape) should be 1-D tensor."
);
PADDLE_ENFORCE_EQ
(
output_shape_dims
.
size
(),
1
,
platform
::
errors
::
InvalidArgument
(
"The dimesions size of input OutputShape in AffineGridOp should "
"be 1. But received OutputShape's dimesions size=[%d], "
"OutputShape's dimesions=[%s]"
,
output_shape_dims
.
size
(),
output_shape_dims
));
}
else
{
PADDLE_ENFORCE
(
output_shape
.
size
()
==
4
,
"The size of attr(output_shape) should be 4."
);
PADDLE_ENFORCE_EQ
(
output_shape
.
size
(),
4
,
platform
::
errors
::
InvalidArgument
(
"The size of attribute 'output_shape' in AffineGridOp should be "
"4. But received output_shape's size=[%d]."
,
output_shape
.
size
()));
}
PADDLE_ENFORCE
(
theta_dims
[
1
]
==
2
,
"Input(theta) dims[1] should be 2."
);
PADDLE_ENFORCE
(
theta_dims
[
2
]
==
3
,
"Input(theta) dims[2] should be 3."
);
PADDLE_ENFORCE_EQ
(
theta_dims
[
1
],
2
,
platform
::
errors
::
InvalidArgument
(
"The second dimesion of input 'theta' in AffineGridOp should be 2. "
"But received second dimesion=[%d], dimesions=[%s]"
,
theta_dims
[
1
],
theta_dims
));
PADDLE_ENFORCE_EQ
(
theta_dims
[
2
],
3
,
platform
::
errors
::
InvalidArgument
(
"The third dimesion of input 'theta' in AffineGridOp should be 3. "
"But received third dimesion=[%d], dimesions=[%s]"
,
theta_dims
[
2
],
theta_dims
));
// N * H * W * 2
ctx
->
SetOutputDim
(
"Output"
,
framework
::
make_ddim
({
theta_dims
[
0
],
-
1
,
-
1
,
2
}));
...
...
paddle/fluid/operators/detection/generate_proposal_labels_op.cc
浏览文件 @
5fc42753
...
...
@@ -38,42 +38,64 @@ class GenerateProposalLabelsOp : public framework::OperatorWithKernel {
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"RpnRois"
),
"Input(RpnRois) shouldn't be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"GtClasses"
),
"Input(GtClasses) shouldn't be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"IsCrowd"
),
"Input(IsCrowd) shouldn't be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"GtBoxes"
),
"Input(GtBoxes) shouldn't be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"ImInfo"
),
"Input(ImInfo) shouldn't be null."
);
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"Rois"
),
"Output(Rois) of GenerateProposalLabelsOp should not be null"
);
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"LabelsInt32"
),
"Output(LabelsInt32) of GenerateProposalLabelsOp should not be null"
);
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"BboxTargets"
),
"Output(BboxTargets) of GenerateProposalLabelsOp should not be null"
);
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"BboxInsideWeights"
),
"Output(BboxInsideWeights) of GenerateProposalLabelsOp "
"should not be null"
);
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"BboxOutsideWeights"
),
"Output(BboxOutsideWeights) of GenerateProposalLabelsOp "
"should not be null"
);
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"RpnRois"
),
true
,
platform
::
errors
::
NotFound
(
"Input(RpnRois) shouldn't be null."
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"GtClasses"
),
true
,
platform
::
errors
::
NotFound
(
"Input(GtClasses) shouldn't be null."
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"IsCrowd"
),
true
,
platform
::
errors
::
NotFound
(
"Input(IsCrowd) shouldn't be null."
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"GtBoxes"
),
true
,
platform
::
errors
::
NotFound
(
"Input(GtBoxes) shouldn't be null."
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"ImInfo"
),
true
,
platform
::
errors
::
NotFound
(
"Input(ImInfo) shouldn't be null."
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasOutput
(
"Rois"
),
true
,
platform
::
errors
::
NotFound
(
"Output(Rois) of GenerateProposalLabelsOp should not be null"
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasOutput
(
"LabelsInt32"
),
true
,
platform
::
errors
::
NotFound
(
"Output(LabelsInt32) of "
"GenerateProposalLabelsOp "
"should not be null"
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasOutput
(
"BboxTargets"
),
true
,
platform
::
errors
::
NotFound
(
"Output(BboxTargets) of "
"GenerateProposalLabelsOp "
"should not be null"
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasOutput
(
"BboxInsideWeights"
),
true
,
platform
::
errors
::
NotFound
(
"Output(BboxInsideWeights) of GenerateProposalLabelsOp "
"should not be null"
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasOutput
(
"BboxOutsideWeights"
),
true
,
platform
::
errors
::
NotFound
(
"Output(BboxOutsideWeights) of GenerateProposalLabelsOp "
"should not be null"
));
auto
rpn_rois_dims
=
ctx
->
GetInputDim
(
"RpnRois"
);
auto
gt_boxes_dims
=
ctx
->
GetInputDim
(
"GtBoxes"
);
auto
im_info_dims
=
ctx
->
GetInputDim
(
"ImInfo"
);
PADDLE_ENFORCE_EQ
(
rpn_rois_dims
.
size
(),
2
,
"The rank of Input(RpnRois) must be 2."
);
platform
::
errors
::
InvalidArgument
(
"The dimensions size of Input(RpnRois) must be 2. "
"But received dimensions size=[%d], dimensions=[%s]."
,
rpn_rois_dims
.
size
(),
rpn_rois_dims
));
PADDLE_ENFORCE_EQ
(
gt_boxes_dims
.
size
(),
2
,
"The rank of Input(GtBoxes) must be 2."
);
platform
::
errors
::
InvalidArgument
(
"The dimensions size of Input(GtBoxes) must be 2. "
"But received dimensions size=[%d], dimensions=[%s]."
,
gt_boxes_dims
.
size
(),
gt_boxes_dims
));
PADDLE_ENFORCE_EQ
(
im_info_dims
.
size
(),
2
,
"The rank of Input(ImInfo) must be 2."
);
platform
::
errors
::
InvalidArgument
(
"The dimensions size of Input(ImInfo) must be 2. But "
"received dimensions size=[%d], dimensions=[%s]."
,
im_info_dims
.
size
(),
im_info_dims
));
int
class_nums
=
ctx
->
Attrs
().
Get
<
int
>
(
"class_nums"
);
...
...
@@ -399,15 +421,30 @@ class GenerateProposalLabelsKernel : public framework::OpKernel<T> {
bool
use_random
=
context
.
Attr
<
bool
>
(
"use_random"
);
bool
is_cascade_rcnn
=
context
.
Attr
<
bool
>
(
"is_cascade_rcnn"
);
bool
is_cls_agnostic
=
context
.
Attr
<
bool
>
(
"is_cls_agnostic"
);
PADDLE_ENFORCE_EQ
(
rpn_rois
->
lod
().
size
(),
1UL
,
"GenerateProposalLabelsOp rpn_rois needs 1 level of LoD"
);
PADDLE_ENFORCE_EQ
(
rpn_rois
->
lod
().
size
(),
1UL
,
platform
::
errors
::
InvalidArgument
(
"GenerateProposalLabelsOp rpn_rois needs 1 level of LoD. But "
"received level of LoD is [%d], LoD is [%s]."
,
rpn_rois
->
lod
().
size
(),
rpn_rois
->
lod
()));
PADDLE_ENFORCE_EQ
(
gt_classes
->
lod
().
size
(),
1UL
,
"GenerateProposalLabelsOp gt_classes needs 1 level of LoD"
);
PADDLE_ENFORCE_EQ
(
is_crowd
->
lod
().
size
(),
1UL
,
"GenerateProposalLabelsOp is_crowd needs 1 level of LoD"
);
PADDLE_ENFORCE_EQ
(
gt_boxes
->
lod
().
size
(),
1UL
,
"GenerateProposalLabelsOp gt_boxes needs 1 level of LoD"
);
platform
::
errors
::
InvalidArgument
(
"GenerateProposalLabelsOp gt_classes needs 1 level of LoD. But "
"received level of LoD is [%d], LoD is [%s]."
,
gt_classes
->
lod
().
size
(),
gt_classes
->
lod
()));
PADDLE_ENFORCE_EQ
(
is_crowd
->
lod
().
size
(),
1UL
,
platform
::
errors
::
InvalidArgument
(
"GenerateProposalLabelsOp is_crowd needs 1 level of LoD. But "
"received level of LoD is [%d], LoD is [%s]."
,
is_crowd
->
lod
().
size
(),
is_crowd
->
lod
()));
PADDLE_ENFORCE_EQ
(
gt_boxes
->
lod
().
size
(),
1UL
,
platform
::
errors
::
InvalidArgument
(
"GenerateProposalLabelsOp gt_boxes needs 1 level of LoD. But "
"received level of LoD is [%d], LoD is [%s]."
,
gt_boxes
->
lod
().
size
(),
gt_boxes
->
lod
()));
int64_t
n
=
static_cast
<
int64_t
>
(
rpn_rois
->
lod
().
back
().
size
()
-
1
);
rois
->
mutable_data
<
T
>
({
n
*
batch_size_per_im
,
kBoxDim
},
context
.
GetPlace
());
...
...
paddle/fluid/operators/detection/generate_proposals_op.cc
浏览文件 @
5fc42753
...
...
@@ -43,14 +43,21 @@ class GenerateProposalsOp : public framework::OperatorWithKernel {
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"Scores"
),
"Input(Scores) shouldn't be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"BboxDeltas"
),
"Input(BboxDeltas) shouldn't be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"ImInfo"
),
"Input(ImInfo) shouldn't be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"Anchors"
),
"Input(Anchors) shouldn't be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"Variances"
),
"Input(Variances) shouldn't be null."
);
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"Scores"
),
true
,
platform
::
errors
::
NotFound
(
"Input(Scores) shouldn't be null."
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"BboxDeltas"
),
true
,
platform
::
errors
::
NotFound
(
"Input(BboxDeltas) shouldn't be null."
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"ImInfo"
),
true
,
platform
::
errors
::
NotFound
(
"Input(ImInfo) shouldn't be null."
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"Anchors"
),
true
,
platform
::
errors
::
NotFound
(
"Input(Anchors) shouldn't be null."
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"Variances"
),
true
,
platform
::
errors
::
NotFound
(
"Input(Variances) shouldn't be null."
));
ctx
->
SetOutputDim
(
"RpnRois"
,
{
-
1
,
4
});
ctx
->
SetOutputDim
(
"RpnRoiProbs"
,
{
-
1
,
1
});
...
...
@@ -247,7 +254,6 @@ static inline Tensor VectorToTensor(const std::vector<T> &selected_indices,
template
<
class
T
>
static
inline
Tensor
NMS
(
const
platform
::
DeviceContext
&
ctx
,
Tensor
*
bbox
,
Tensor
*
scores
,
T
nms_threshold
,
float
eta
)
{
PADDLE_ENFORCE_NOT_NULL
(
bbox
);
int64_t
num_boxes
=
bbox
->
dims
()[
0
];
// 4: [xmin ymin xmax ymax]
int64_t
box_size
=
bbox
->
dims
()[
1
];
...
...
paddle/fluid/operators/detection/generate_proposals_op.cu
浏览文件 @
5fc42753
...
...
@@ -379,7 +379,11 @@ class CUDAGenerateProposalsKernel : public framework::OpKernel<T> {
float
nms_thresh
=
context
.
Attr
<
float
>
(
"nms_thresh"
);
float
min_size
=
context
.
Attr
<
float
>
(
"min_size"
);
float
eta
=
context
.
Attr
<
float
>
(
"eta"
);
PADDLE_ENFORCE_GE
(
eta
,
1.
,
"Not support adaptive NMS."
);
PADDLE_ENFORCE_GE
(
eta
,
1.
,
platform
::
errors
::
InvalidArgument
(
"Not support adaptive NMS. The attribute 'eta' "
"should not less than 1. But received eta=[%d]"
,
eta
));
auto
&
dev_ctx
=
context
.
template
device_context
<
DeviceContext
>();
...
...
paddle/fluid/operators/detection/rpn_target_assign_op.cc
浏览文件 @
5fc42753
...
...
@@ -31,40 +31,44 @@ class RpnTargetAssignOp : public framework::OperatorWithKernel {
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"Anchor"
),
"Input(Anchor) of RpnTargetAssignOp should not be null"
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"GtBoxes"
),
"Input(GtBoxes) of RpnTargetAssignOp should not be null"
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"IsCrowd"
),
"Input(Anchor) of RpnTargetAssignOp should not be null"
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"ImInfo"
),
"Input(ImInfo) of RpnTargetAssignOp should not be null"
);
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"LocationIndex"
),
"Output(LocationIndex) of RpnTargetAssignOp should not be null"
);
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"ScoreIndex"
),
"Output(ScoreIndex) of RpnTargetAssignOp should not be null"
);
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"TargetLabel"
),
"Output(TargetLabel) of RpnTargetAssignOp should not be null"
);
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"TargetBBox"
),
"Output(TargetBBox) of RpnTargetAssignOp should not be null"
);
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"BBoxInsideWeight"
),
"Output(BBoxInsideWeight) of RpnTargetAssignOp should not be null"
);
OP_INOUT_CHECK
(
ctx
->
HasInput
(
"Anchor"
),
"Input"
,
"Anchor"
,
"rpn_target_assign"
);
OP_INOUT_CHECK
(
ctx
->
HasInput
(
"GtBoxes"
),
"Input"
,
"GtBoxes"
,
"rpn_target_assign"
);
OP_INOUT_CHECK
(
ctx
->
HasInput
(
"IsCrowd"
),
"Input"
,
"IsCrowd"
,
"rpn_target_assign"
);
OP_INOUT_CHECK
(
ctx
->
HasInput
(
"ImInfo"
),
"Input"
,
"ImInfo"
,
"rpn_target_assign"
);
OP_INOUT_CHECK
(
ctx
->
HasOutput
(
"LocationIndex"
),
"Output"
,
"LocationIndex"
,
"rpn_target_assign"
);
OP_INOUT_CHECK
(
ctx
->
HasOutput
(
"ScoreIndex"
),
"Output"
,
"ScoreIndex"
,
"rpn_target_assign"
);
OP_INOUT_CHECK
(
ctx
->
HasOutput
(
"TargetLabel"
),
"Output"
,
"TargetLabel"
,
"rpn_target_assign"
);
OP_INOUT_CHECK
(
ctx
->
HasOutput
(
"TargetBBox"
),
"Output"
,
"TargetBBox"
,
"rpn_target_assign"
);
OP_INOUT_CHECK
(
ctx
->
HasOutput
(
"BBoxInsideWeight"
),
"Output"
,
"BBoxInsideWeight"
,
"rpn_target_assign"
);
auto
anchor_dims
=
ctx
->
GetInputDim
(
"Anchor"
);
auto
gt_boxes_dims
=
ctx
->
GetInputDim
(
"GtBoxes"
);
auto
im_info_dims
=
ctx
->
GetInputDim
(
"ImInfo"
);
PADDLE_ENFORCE_EQ
(
anchor_dims
.
size
(),
2
,
"The rank of Input(Anchor) must be 2."
);
platform
::
errors
::
InvalidArgument
(
"The dimensions size of Input(Anchor) must be 2. But "
"received dimensions size=[%d], dimensions=[%s]."
,
anchor_dims
.
size
(),
anchor_dims
));
PADDLE_ENFORCE_EQ
(
gt_boxes_dims
.
size
(),
2
,
"The rank of Input(GtBoxes) must be 2."
);
platform
::
errors
::
InvalidArgument
(
"The dimensions size of Input(GtBoxes) must be 2. "
"But received dimensions size=[%d], dimensions=[%s]."
,
gt_boxes_dims
.
size
(),
gt_boxes_dims
));
PADDLE_ENFORCE_EQ
(
im_info_dims
.
size
(),
2
,
"The rank of Input(ImInfo) must be 2."
);
platform
::
errors
::
InvalidArgument
(
"The dimensions size of Input(ImInfo) must be 2. But "
"received dimensions size=[%d], dimensions=[%s]."
,
im_info_dims
.
size
(),
im_info_dims
));
ctx
->
SetOutputDim
(
"LocationIndex"
,
{
-
1
});
ctx
->
SetOutputDim
(
"ScoreIndex"
,
{
-
1
});
...
...
@@ -357,9 +361,15 @@ class RpnTargetAssignKernel : public framework::OpKernel<T> {
auto
*
bbox_inside_weight
=
context
.
Output
<
LoDTensor
>
(
"BBoxInsideWeight"
);
PADDLE_ENFORCE_EQ
(
gt_boxes
->
lod
().
size
(),
1UL
,
"RpnTargetAssignOp gt_boxes needs 1 level of LoD"
);
platform
::
errors
::
InvalidArgument
(
"RpnTargetAssignOp gt_boxes needs 1 level of LoD. "
"But received level of LoD is [%d], LoD is [%s]."
,
gt_boxes
->
lod
().
size
(),
gt_boxes
->
lod
()));
PADDLE_ENFORCE_EQ
(
is_crowd
->
lod
().
size
(),
1UL
,
"RpnTargetAssignOp is_crowd needs 1 level of LoD"
);
platform
::
errors
::
InvalidArgument
(
"RpnTargetAssignOp is_crowd needs 1 level of LoD. "
"But received level of LoD is [%d], LoD is [%s]."
,
is_crowd
->
lod
().
size
(),
is_crowd
->
lod
()));
int64_t
anchor_num
=
static_cast
<
int64_t
>
(
anchor
->
dims
()[
0
]);
int64_t
batch_num
=
static_cast
<
int64_t
>
(
gt_boxes
->
lod
().
back
().
size
()
-
1
);
...
...
@@ -479,8 +489,20 @@ class RpnTargetAssignKernel : public framework::OpKernel<T> {
lod0_score
.
emplace_back
(
total_score_num
);
}
PADDLE_ENFORCE_LE
(
total_loc_num
,
max_num
);
PADDLE_ENFORCE_LE
(
total_score_num
,
max_num
);
PADDLE_ENFORCE_LE
(
total_loc_num
,
max_num
,
platform
::
errors
::
InvalidArgument
(
"The number of sampled bboxes should not be greater than the "
"number of all anchor boxes(%d), but the number of sampled "
"bboxes is :%d."
,
max_num
,
total_loc_num
));
PADDLE_ENFORCE_LE
(
total_score_num
,
max_num
,
platform
::
errors
::
InvalidArgument
(
"The number of sampled scores should not be greater than the "
"number of all anchor boxes(%d), but the number of sampled "
"scores is :%d."
,
max_num
,
total_score_num
));
lod_loc
.
emplace_back
(
lod0_loc
);
loc_score
.
emplace_back
(
lod0_score
);
...
...
paddle/fluid/operators/im2sequence_op.cc
浏览文件 @
5fc42753
...
...
@@ -26,14 +26,20 @@ class Im2SequenceOp : public framework::OperatorWithKernel {
protected:
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X"
),
"Input(X) of Im2SequenceOp should not be null."
);
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"Out"
),
"Output(Out) of Im2SequenceOp op should not be null."
);
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"X"
),
true
,
platform
::
errors
::
NotFound
(
"The input 'X' of Im2SequenceOp is not found."
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasOutput
(
"Out"
),
true
,
platform
::
errors
::
NotFound
(
"The output 'Out' of Im2SequenceOp is not found."
));
auto
in_dim
=
ctx
->
GetInputDim
(
"X"
);
PADDLE_ENFORCE_EQ
(
in_dim
.
size
(),
4
,
"Input(X) format must be 4D tensor, eg., NCHW."
);
PADDLE_ENFORCE_EQ
(
in_dim
.
size
(),
4
,
platform
::
errors
::
InvalidArgument
(
"The dimesions size of input 'X' in Im2SequenceOp should be 4. But "
"received dimesions size=[%d], dimesions=[%s]."
,
in_dim
.
size
(),
in_dim
));
auto
img_channels
=
in_dim
[
1
];
auto
kernels
=
ctx
->
Attrs
().
Get
<
std
::
vector
<
int
>>
(
"kernels"
);
...
...
@@ -146,9 +152,13 @@ class Im2SequenceGradOp : public framework::OperatorWithKernel {
protected:
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X"
),
"Input(X) should not be null"
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
framework
::
GradVarName
(
"Out"
)),
"Input(Out@GRAD) shouldn't be null."
);
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"X"
),
true
,
platform
::
errors
::
NotFound
(
"The input 'X' of Im2SequenceGradOp is not found."
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
framework
::
GradVarName
(
"Out"
)),
true
,
platform
::
errors
::
NotFound
(
"The input %s of Im2SequenceGradOp is not found."
,
framework
::
GradVarName
(
"Out"
)));
ctx
->
SetOutputDim
(
framework
::
GradVarName
(
"X"
),
ctx
->
GetInputDim
(
"X"
));
}
};
...
...
paddle/fluid/operators/label_smooth_op.cc
浏览文件 @
5fc42753
...
...
@@ -28,18 +28,24 @@ class LabelSmoothOp : public framework::OperatorWithKernel {
:
OperatorWithKernel
(
type
,
inputs
,
outputs
,
attrs
)
{}
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X"
),
"Input(X) of LabelSmoothOp should not be null."
);
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"Out"
),
"Output(Out) of LabelSmoothOp should not be null."
);
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"X"
),
true
,
platform
::
errors
::
NotFound
(
"The input 'X' of LabelSmoothOp is not found."
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasOutput
(
"Out"
),
true
,
platform
::
errors
::
NotFound
(
"The output 'Out' of LabelSmoothOp is not found."
));
auto
in_dims
=
ctx
->
GetInputDim
(
"X"
);
if
(
ctx
->
HasInput
(
"PriorDist"
))
{
auto
noise_dims
=
ctx
->
GetInputDim
(
"PriorDist"
);
auto
noise_numel
=
paddle
::
framework
::
product
(
noise_dims
);
PADDLE_ENFORCE
(
in_dims
[
in_dims
.
size
()
-
1
]
==
noise_numel
,
"The number of elements in Input(PriorDist) must be equal to the "
"dimension of each label."
);
PADDLE_ENFORCE_EQ
(
in_dims
[
in_dims
.
size
()
-
1
],
noise_numel
,
platform
::
errors
::
InvalidArgument
(
"The number of elements in input 'PriorDist' must be equal to "
"the "
"dimension of each label. But received each label's "
"dimension=[%d], number of elements in input 'PriorDist' is [%d]"
,
in_dims
[
in_dims
.
size
()
-
1
],
noise_numel
));
}
ctx
->
ShareLoD
(
"X"
,
/*->*/
"Out"
);
ctx
->
SetOutputDim
(
"Out"
,
in_dims
);
...
...
python/paddle/fluid/layers/detection.py
浏览文件 @
5fc42753
...
...
@@ -406,6 +406,22 @@ def rpn_target_assign(bbox_pred,
"""
helper
=
LayerHelper
(
'rpn_target_assign'
,
**
locals
())
check_variable_and_dtype
(
bbox_pred
,
'bbox_pred'
,
[
'float32'
,
'float64'
],
'rpn_target_assign'
)
check_variable_and_dtype
(
cls_logits
,
'cls_logits'
,
[
'float32'
,
'float64'
],
'rpn_target_assign'
)
check_variable_and_dtype
(
anchor_box
,
'anchor_box'
,
[
'float32'
,
'float64'
],
'rpn_target_assign'
)
check_variable_and_dtype
(
anchor_var
,
'anchor_var'
,
[
'float32'
,
'float64'
],
'rpn_target_assign'
)
check_variable_and_dtype
(
gt_boxes
,
'gt_boxes'
,
[
'float32'
,
'float64'
],
'rpn_target_assign'
)
check_variable_and_dtype
(
is_crowd
,
'is_crowd'
,
[
'int32'
],
'rpn_target_assign'
)
check_variable_and_dtype
(
im_info
,
'im_info'
,
[
'float32'
,
'float64'
],
'rpn_target_assign'
)
# Assign target label to anchors
loc_index
=
helper
.
create_variable_for_type_inference
(
dtype
=
'int32'
)
score_index
=
helper
.
create_variable_for_type_inference
(
dtype
=
'int32'
)
...
...
@@ -2541,6 +2557,13 @@ def generate_proposal_labels(rpn_rois,
helper
=
LayerHelper
(
'generate_proposal_labels'
,
**
locals
())
check_variable_and_dtype
(
rpn_rois
,
'rpn_rois'
,
[
'float32'
,
'float64'
],
'generate_proposal_labels'
)
check_variable_and_dtype
(
gt_classes
,
'gt_classes'
,
[
'int32'
],
'generate_proposal_labels'
)
check_variable_and_dtype
(
is_crowd
,
'is_crowd'
,
[
'int32'
],
'generate_proposal_labels'
)
rois
=
helper
.
create_variable_for_type_inference
(
dtype
=
rpn_rois
.
dtype
)
labels_int32
=
helper
.
create_variable_for_type_inference
(
dtype
=
gt_classes
.
dtype
)
...
...
@@ -2775,7 +2798,7 @@ def generate_proposals(scores,
im_info(Variable): A 2-D Tensor with shape [N, 3] represents origin
image information for N batch. Height and width are the input sizes
and scale is the ratio of network input size and original size.
The data type
must be int32
.
The data type
can be float32 or float64
.
anchors(Variable): A 4-D Tensor represents the anchors with a layout
of [H, W, A, 4]. H and W are height and width of the feature map,
num_anchors is the box count of each position. Each anchor is
...
...
@@ -2818,6 +2841,17 @@ def generate_proposals(scores,
"""
helper
=
LayerHelper
(
'generate_proposals'
,
**
locals
())
check_variable_and_dtype
(
scores
,
'scores'
,
[
'float32'
],
'generate_proposals'
)
check_variable_and_dtype
(
bbox_deltas
,
'bbox_deltas'
,
[
'float32'
],
'generate_proposals'
)
check_variable_and_dtype
(
im_info
,
'im_info'
,
[
'float32'
,
'float64'
],
'generate_proposals'
)
check_variable_and_dtype
(
anchors
,
'anchors'
,
[
'float32'
],
'generate_proposals'
)
check_variable_and_dtype
(
variances
,
'variances'
,
[
'float32'
],
'generate_proposals'
)
rpn_rois
=
helper
.
create_variable_for_type_inference
(
dtype
=
bbox_deltas
.
dtype
)
rpn_roi_probs
=
helper
.
create_variable_for_type_inference
(
...
...
python/paddle/fluid/layers/nn.py
浏览文件 @
5fc42753
...
...
@@ -6878,6 +6878,8 @@ def im2sequence(input,
assert not in_dygraph_mode(), (
"sequence layer is not supported in dygraph mode yet.")
check_variable_and_dtype(input, 'input', ['float32'], 'im2sequence')
if isinstance(filter_size, int):
filter_size = [filter_size, filter_size]
if isinstance(stride, int):
...
...
@@ -8032,7 +8034,7 @@ def label_smooth(label,
label(Variable): The input variable containing the label data. The
label data should use one-hot representation. It's
a multidimensional tensor with a shape of
:math:`[N_1, ..., Depth]`, where Depth is class number.
:math:`[N_1, ..., Depth]`, where Depth is class number.
The dtype can be "float32" and "float64".
prior_dist(Variable, optional): The prior distribution to be used to smooth
labels. If not provided, an uniform distribution
is used. It's a multidimensional tensor with a shape of
...
...
@@ -8055,7 +8057,7 @@ def label_smooth(label,
import paddle.fluid as fluid
import paddle.fluid.layers as layers
label = layers.data(name="label", shape=[1], dtype="
floa
t32")
label = layers.data(name="label", shape=[1], dtype="
in
t32")
one_hot_label = layers.one_hot(input=label, depth=10)
smooth_label = layers.label_smooth(
label=one_hot_label, epsilon=0.1, dtype="float32")
...
...
@@ -8067,6 +8069,9 @@ def label_smooth(label,
return core.ops.label_smooth(label, prior_dist, 'epsilon',
float(epsilon))
check_variable_and_dtype(label, 'label', ['float32', 'float64'],
'label_smooth')
helper = LayerHelper("label_smooth", **locals())
label.stop_gradient = True
smooth_label = helper.create_variable_for_type_inference(dtype)
...
...
@@ -10182,6 +10187,9 @@ def affine_grid(theta, out_shape, name=None):
"""
helper = LayerHelper('affine_grid')
check_variable_and_dtype(theta, 'theta', ['float32', 'float64'],
'affine_grid')
if not (isinstance(out_shape, list) or isinstance(out_shape, tuple) or \
isinstance(out_shape, Variable)):
raise ValueError("The out_shape should be a list, tuple or Variable.")
...
...
@@ -10194,6 +10202,8 @@ def affine_grid(theta, out_shape, name=None):
attrs = {}
if isinstance(out_shape, Variable):
ipts['OutputShape'] = out_shape
check_variable_and_dtype(out_shape, 'out_shape', ['int32'],
'affine_grid')
else:
attrs['output_shape'] = out_shape
...
...
python/paddle/fluid/tests/unittests/test_layers.py
浏览文件 @
5fc42753
...
...
@@ -3000,8 +3000,7 @@ class TestBook(LayerTest):
out
,
ids
=
layers
.
argsort
(
input
=
data
,
axis
=
1
)
theta
=
layers
.
data
(
name
=
"theta"
,
shape
=
[
2
,
3
],
dtype
=
"float32"
)
out_shape
=
layers
.
data
(
name
=
"out_shape"
,
shape
=
[
-
1
],
dtype
=
"float32"
)
out_shape
=
layers
.
data
(
name
=
"out_shape"
,
shape
=
[
-
1
],
dtype
=
"int32"
)
data_0
=
layers
.
affine_grid
(
theta
,
out_shape
)
data_1
=
layers
.
affine_grid
(
theta
,
[
5
,
3
,
28
,
28
])
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录