Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
8abc5333
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看板
未验证
提交
8abc5333
编写于
4月 09, 2023
作者:
S
scotty
提交者:
GitHub
4月 09, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add autogen code support for matrix_nms. (#52479)
* add autogen code support for matrix_nms. * update
上级
e1692dc7
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
35 addition
and
190 deletion
+35
-190
paddle/fluid/operators/detection/CMakeLists.txt
paddle/fluid/operators/detection/CMakeLists.txt
+0
-1
paddle/fluid/operators/detection/matrix_nms_op.cc
paddle/fluid/operators/detection/matrix_nms_op.cc
+0
-146
paddle/fluid/operators/generator/get_expected_kernel_func.cc
paddle/fluid/operators/generator/get_expected_kernel_func.cc
+7
-0
paddle/fluid/operators/generator/get_expected_kernel_func.h
paddle/fluid/operators/generator/get_expected_kernel_func.h
+4
-0
paddle/phi/api/yaml/legacy_ops.yaml
paddle/phi/api/yaml/legacy_ops.yaml
+0
-8
paddle/phi/api/yaml/op_compat.yaml
paddle/phi/api/yaml/op_compat.yaml
+8
-0
paddle/phi/api/yaml/op_version.yaml
paddle/phi/api/yaml/op_version.yaml
+7
-0
paddle/phi/api/yaml/ops.yaml
paddle/phi/api/yaml/ops.yaml
+9
-0
paddle/phi/ops/compat/matrix_nms_sig.cc
paddle/phi/ops/compat/matrix_nms_sig.cc
+0
-35
未找到文件。
paddle/fluid/operators/detection/CMakeLists.txt
浏览文件 @
8abc5333
...
...
@@ -58,7 +58,6 @@ detection_library(generate_proposal_labels_op SRCS
generate_proposal_labels_op.cc
)
detection_library
(
multiclass_nms_op SRCS multiclass_nms_op.cc DEPS gpc
)
detection_library
(
locality_aware_nms_op SRCS locality_aware_nms_op.cc DEPS gpc
)
detection_library
(
matrix_nms_op SRCS matrix_nms_op.cc DEPS gpc
)
detection_library
(
box_clip_op SRCS box_clip_op.cc box_clip_op.cu
)
detection_library
(
yolov3_loss_op SRCS yolov3_loss_op.cc
)
detection_library
(
box_decoder_and_assign_op SRCS box_decoder_and_assign_op.cc
...
...
paddle/fluid/operators/detection/matrix_nms_op.cc
已删除
100644 → 0
浏览文件 @
e1692dc7
/* Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
limitations under the License. */
#include "paddle/fluid/framework/infershape_utils.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/framework/op_version_registry.h"
#include "paddle/phi/infermeta/binary.h"
#include "paddle/phi/kernels/funcs/detection/nms_util.h"
namespace
paddle
{
namespace
operators
{
class
MatrixNMSOp
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
protected:
phi
::
KernelKey
GetExpectedKernelType
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
return
phi
::
KernelKey
(
OperatorWithKernel
::
IndicateVarDataType
(
ctx
,
"Scores"
),
platform
::
CPUPlace
());
}
};
class
MatrixNMSOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
public:
void
Make
()
override
{
AddInput
(
"BBoxes"
,
"(Tensor) A 3-D Tensor with shape "
"[N, M, 4] represents the predicted locations of M bounding boxes"
", N is the batch size. "
"Each bounding box has four coordinate values and the layout is "
"[xmin, ymin, xmax, ymax], when box size equals to 4."
);
AddInput
(
"Scores"
,
"(Tensor) A 3-D Tensor with shape [N, C, M] represents the "
"predicted confidence predictions. N is the batch size, C is the "
"class number, M is number of bounding boxes. For each category "
"there are total M scores which corresponding M bounding boxes. "
" Please note, M is equal to the 2nd dimension of BBoxes. "
);
AddAttr
<
int
>
(
"background_label"
,
"(int, default: 0) "
"The index of background label, the background label will be ignored. "
"If set to -1, then all categories will be considered."
)
.
SetDefault
(
0
);
AddAttr
<
float
>
(
"score_threshold"
,
"(float) "
"Threshold to filter out bounding boxes with low "
"confidence score."
);
AddAttr
<
float
>
(
"post_threshold"
,
"(float, default 0.) "
"Threshold to filter out bounding boxes with low "
"confidence score AFTER decaying."
)
.
SetDefault
(
0.
);
AddAttr
<
int
>
(
"nms_top_k"
,
"(int64_t) "
"Maximum number of detections to be kept according to the "
"confidences after the filtering detections based on "
"score_threshold"
);
AddAttr
<
int
>
(
"keep_top_k"
,
"(int64_t) "
"Number of total bboxes to be kept per image after NMS "
"step. -1 means keeping all bboxes after NMS step."
);
AddAttr
<
bool
>
(
"normalized"
,
"(bool, default true) "
"Whether detections are normalized."
)
.
SetDefault
(
true
);
AddAttr
<
bool
>
(
"use_gaussian"
,
"(bool, default false) "
"Whether to use Gaussian as decreasing function."
)
.
SetDefault
(
false
);
AddAttr
<
float
>
(
"gaussian_sigma"
,
"(float) "
"Sigma for Gaussian decreasing function, only takes effect "
"when 'use_gaussian' is enabled."
)
.
SetDefault
(
2.
);
AddOutput
(
"Out"
,
"(phi::DenseTensor) A 2-D phi::DenseTensor with shape [No, 6] "
"represents the "
"detections. Each row has 6 values: "
"[label, confidence, xmin, ymin, xmax, ymax]. "
"the offsets in first dimension are called LoD, the number of "
"offset is N + 1, if LoD[i + 1] - LoD[i] == 0, means there is "
"no detected bbox."
);
AddOutput
(
"Index"
,
"(phi::DenseTensor) A 2-D phi::DenseTensor with shape [No, 1] "
"represents the "
"index of selected bbox. The index is the absolute index cross "
"batches."
);
AddOutput
(
"RoisNum"
,
"(Tensor), Number of RoIs in each images."
)
.
AsDispensable
();
AddComment
(
R"DOC(
This operator does multi-class matrix non maximum suppression (NMS) on batched
boxes and scores.
In the NMS step, this operator greedily selects a subset of detection bounding
boxes that have high scores larger than score_threshold, if providing this
threshold, then selects the largest nms_top_k confidences scores if nms_top_k
is larger than -1. Then this operator decays boxes score according to the
Matrix NMS scheme.
Aftern NMS step, at most keep_top_k number of total bboxes are to be kept
per image if keep_top_k is larger than -1.
This operator support multi-class and batched inputs. It applying NMS
independently for each class. The outputs is a 2-D LoDTenosr, for each
image, the offsets in first dimension of phi::DenseTensor are called LoD, the number
of offset is N + 1, where N is the batch size. If LoD[i + 1] - LoD[i] == 0,
means there is no detected bbox for this image. Now this operator has one more
output, which is RoisNum. The size of RoisNum is N, RoisNum[i] means the number of
detected bbox for this image.
For more information on Matrix NMS, please refer to:
https://arxiv.org/abs/2003.10152
)DOC"
);
}
};
}
// namespace operators
}
// namespace paddle
DECLARE_INFER_SHAPE_FUNCTOR
(
matrix_nms
,
MatrixNMSInferShapeFunctor
,
PD_INFER_META
(
phi
::
MatrixNMSInferMeta
));
namespace
ops
=
paddle
::
operators
;
REGISTER_OPERATOR
(
matrix_nms
,
ops
::
MatrixNMSOp
,
ops
::
MatrixNMSOpMaker
,
paddle
::
framework
::
EmptyGradOpMaker
<
paddle
::
framework
::
OpDesc
>
,
paddle
::
framework
::
EmptyGradOpMaker
<
paddle
::
imperative
::
OpBase
>
,
MatrixNMSInferShapeFunctor
);
REGISTER_OP_VERSION
(
matrix_nms
)
.
AddCheckpoint
(
R"ROC(Upgrade matrix_nms: add a new output [RoisNum].)ROC"
,
paddle
::
framework
::
compatible
::
OpVersionDesc
().
NewOutput
(
"RoisNum"
,
"The number of RoIs in each image."
));
paddle/fluid/operators/generator/get_expected_kernel_func.cc
浏览文件 @
8abc5333
...
...
@@ -151,5 +151,12 @@ phi::KernelKey GetUpdateLossScalingExpectedKernelType(
return
phi
::
KernelKey
(
dtype
,
ctx
.
GetPlace
());
}
phi
::
KernelKey
GetMatrixNmsExpectedKernelType
(
const
framework
::
ExecutionContext
&
ctx
,
const
framework
::
OperatorWithKernel
*
op_ptr
)
{
return
phi
::
KernelKey
(
op_ptr
->
IndicateVarDataType
(
ctx
,
"Scores"
),
platform
::
CPUPlace
());
}
}
// namespace operators
}
// namespace paddle
paddle/fluid/operators/generator/get_expected_kernel_func.h
浏览文件 @
8abc5333
...
...
@@ -40,5 +40,9 @@ phi::KernelKey GetUpdateLossScalingExpectedKernelType(
const
framework
::
ExecutionContext
&
ctx
,
const
framework
::
OperatorWithKernel
*
op_ptr
);
phi
::
KernelKey
GetMatrixNmsExpectedKernelType
(
const
framework
::
ExecutionContext
&
ctx
,
const
framework
::
OperatorWithKernel
*
op_ptr
);
}
// namespace operators
}
// namespace paddle
paddle/phi/api/yaml/legacy_ops.yaml
浏览文件 @
8abc5333
...
...
@@ -878,14 +878,6 @@
func
:
matmul
backward
:
matmul_grad
-
op
:
matrix_nms
args
:
(Tensor bboxes, Tensor scores, float score_threshold, int nms_top_k, int keep_top_k, float post_threshold=0., bool use_gaussian =
false
, float gaussian_sigma = 2.0, int background_label = 0, bool normalized =
true
)
output
:
Tensor(out), Tensor(index), Tensor(roisnum)
infer_meta
:
func
:
MatrixNMSInferMeta
kernel
:
func
:
matrix_nms
-
op
:
matrix_rank
args
:
(Tensor x, float tol, bool hermitian=false, bool use_default_tol=true)
output
:
Tensor(out)
...
...
paddle/phi/api/yaml/op_compat.yaml
浏览文件 @
8abc5333
...
...
@@ -1311,6 +1311,14 @@
attrs
:
[
bool use_mkldnn = false
,
float scale_x = 1.0f
,
'
float[]
scale_y
=
{1.0f}'
,
float scale_out = 1.0f
,
bool force_fp32_output = false
]
-
op
:
matrix_nms
inputs
:
{
bboxes
:
BBoxes
,
scores
:
Scores
}
outputs
:
{
out
:
Out
,
index
:
Index
,
roisnum
:
RoisNum
}
get_expected_kernel_type
:
matrix_nms
:
GetMatrixNmsExpectedKernelType
-
op
:
matrix_power
inputs
:
x
:
X
...
...
paddle/phi/api/yaml/op_version.yaml
浏览文件 @
8abc5333
...
...
@@ -138,6 +138,13 @@
comment
:
In order to change output data type
default
:
5
-
op
:
matrix_nms
version
:
-
checkpoint
:
Upgrade matrix_nms, add a new output [RoisNum].
action
:
-
add_output
:
RoisNum
comment
:
The number of RoIs in each image.
-
op
:
not_equal
version
:
-
checkpoint
:
Upgrade compare ops, add a new attribute [force_cpu]
...
...
paddle/phi/api/yaml/ops.yaml
浏览文件 @
8abc5333
...
...
@@ -1066,6 +1066,15 @@
data_type
:
x
backward
:
masked_select_grad
-
op
:
matrix_nms
args
:
(Tensor bboxes, Tensor scores, float score_threshold, int nms_top_k, int keep_top_k, float post_threshold=0., bool use_gaussian =
false
, float gaussian_sigma = 2., int background_label = 0, bool normalized =
true
)
output
:
Tensor(out), Tensor(index), Tensor(roisnum)
infer_meta
:
func
:
MatrixNMSInferMeta
optional
:
roisnum
kernel
:
func
:
matrix_nms
-
op
:
matrix_power
args
:
(Tensor x, int n)
output
:
Tensor
...
...
paddle/phi/ops/compat/matrix_nms_sig.cc
已删除
100644 → 0
浏览文件 @
e1692dc7
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "paddle/phi/core/compat/op_utils.h"
namespace
phi
{
KernelSignature
MatrixNMSOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
)
{
return
KernelSignature
(
"matrix_nms"
,
{
"BBoxes"
,
"Scores"
},
{
"score_threshold"
,
"nms_top_k"
,
"keep_top_k"
,
"post_threshold"
,
"use_gaussian"
,
"gaussian_sigma"
,
"background_label"
,
"normalized"
},
{
"Out"
,
"Index"
,
"RoisNum"
});
}
}
// namespace phi
PD_REGISTER_ARG_MAPPING_FN
(
matrix_nms
,
phi
::
MatrixNMSOpArgumentMapping
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录