Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
ed040a17
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看板
未验证
提交
ed040a17
编写于
4月 26, 2023
作者:
W
Wang Xin
提交者:
GitHub
4月 26, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add autogen code support for box_coder op (#53309)
上级
652d100d
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
15 addition
and
182 deletion
+15
-182
paddle/fluid/operators/detection/CMakeLists.txt
paddle/fluid/operators/detection/CMakeLists.txt
+0
-1
paddle/fluid/operators/detection/box_coder_op.cc
paddle/fluid/operators/detection/box_coder_op.cc
+0
-144
paddle/phi/api/yaml/legacy_ops.yaml
paddle/phi/api/yaml/legacy_ops.yaml
+0
-9
paddle/phi/api/yaml/op_compat.yaml
paddle/phi/api/yaml/op_compat.yaml
+6
-0
paddle/phi/api/yaml/ops.yaml
paddle/phi/api/yaml/ops.yaml
+9
-0
paddle/phi/ops/compat/box_coder_sig.cc
paddle/phi/ops/compat/box_coder_sig.cc
+0
-28
未找到文件。
paddle/fluid/operators/detection/CMakeLists.txt
浏览文件 @
ed040a17
...
@@ -28,7 +28,6 @@ function(detection_library TARGET_NAME)
...
@@ -28,7 +28,6 @@ function(detection_library TARGET_NAME)
PARENT_SCOPE
)
PARENT_SCOPE
)
endfunction
()
endfunction
()
detection_library
(
box_coder_op SRCS box_coder_op.cc
)
detection_library
(
density_prior_box_op SRCS density_prior_box_op.cc
detection_library
(
density_prior_box_op SRCS density_prior_box_op.cc
density_prior_box_op.cu
)
density_prior_box_op.cu
)
...
...
paddle/fluid/operators/detection/box_coder_op.cc
已删除
100644 → 0
浏览文件 @
652d100d
/* Copyright (c) 2018 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 <vector>
#include "paddle/fluid/framework/infershape_utils.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/phi/core/infermeta_utils.h"
#include "paddle/phi/infermeta/ternary.h"
namespace
paddle
{
namespace
operators
{
class
BoxCoderOp
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
};
class
BoxCoderOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
public:
void
Make
()
override
{
AddInput
(
"PriorBox"
,
"(Tensor, default Tensor<float>) "
"Box list PriorBox is a 2-D Tensor with shape [M, 4] holds M boxes, "
"each box is represented as [xmin, ymin, xmax, ymax], "
"[xmin, ymin] is the left top coordinate of the anchor box, "
"if the input is image feature map, they are close to the origin "
"of the coordinate system. [xmax, ymax] is the right bottom "
"coordinate of the anchor box."
);
AddInput
(
"PriorBoxVar"
,
"(Tensor, default Tensor<float>, optional) "
"PriorBoxVar is a 2-D Tensor with shape [M, 4] holds M group "
"of variance. PriorBoxVar will set all elements to 1 by "
"default."
)
.
AsDispensable
();
AddInput
(
"TargetBox"
,
"(phi::DenseTensor or Tensor) This input can be a 2-D phi::DenseTensor "
"with shape "
"[N, 4] when code_type is 'encode_center_size'. This input also can "
"be a 3-D Tensor with shape [N, M, 4] when code_type is "
"'decode_center_size'. [N, 4], each box is represented as "
"[xmin, ymin, xmax, ymax], [xmin, ymin] is the left top coordinate "
"of the box if the input is image feature map, they are close to "
"the origin of the coordinate system. [xmax, ymax] is the right "
"bottom coordinate of the box. This tensor can contain LoD "
"information to represent a batch of inputs. One instance of this "
"batch can contain different numbers of entities."
);
AddAttr
<
std
::
string
>
(
"code_type"
,
"(string, default encode_center_size) "
"the code type used with the target box"
)
.
SetDefault
(
"encode_center_size"
)
.
InEnum
({
"encode_center_size"
,
"decode_center_size"
});
AddAttr
<
bool
>
(
"box_normalized"
,
"(bool, default true) "
"whether treat the priorbox as a normalized box"
)
.
SetDefault
(
true
);
AddAttr
<
int
>
(
"axis"
,
"(int, default 0)"
"which axis in PriorBox to broadcast for box decode,"
"for example, if axis is 0 and TargetBox has shape"
"[N, M, 4] and PriorBox has shape [M, 4], then PriorBox "
"will broadcast to [N, M, 4] for decoding. It is only valid"
"when code type is decode_center_size"
)
.
SetDefault
(
0
)
.
InEnum
({
0
,
1
});
AddAttr
<
std
::
vector
<
float
>>
(
"variance"
,
"(vector<float>, default {}),"
"variance of prior box with shape [4]. PriorBoxVar and variance can"
"not be provided at the same time."
)
.
SetDefault
(
std
::
vector
<
float
>
{});
AddOutput
(
"OutputBox"
,
"(phi::DenseTensor or Tensor) "
"When code_type is 'encode_center_size', the output tensor of "
"box_coder_op with shape [N, M, 4] representing the result of N "
"target boxes encoded with M Prior boxes and variances. When "
"code_type is 'decode_center_size', N represents the batch size "
"and M represents the number of decoded boxes."
);
AddComment
(
R"DOC(
Bounding Box Coder.
Encode/Decode the target bounding box with the priorbox information.
The Encoding schema described below:
ox = (tx - px) / pw / pxv
oy = (ty - py) / ph / pyv
ow = log(abs(tw / pw)) / pwv
oh = log(abs(th / ph)) / phv
The Decoding schema described below:
ox = (pw * pxv * tx * + px) - tw / 2
oy = (ph * pyv * ty * + py) - th / 2
ow = exp(pwv * tw) * pw + tw / 2
oh = exp(phv * th) * ph + th / 2
where `tx`, `ty`, `tw`, `th` denote the target box's center coordinates, width
and height respectively. Similarly, `px`, `py`, `pw`, `ph` denote the
priorbox's (anchor) center coordinates, width and height. `pxv`, `pyv`, `pwv`,
`phv` denote the variance of the priorbox and `ox`, `oy`, `ow`, `oh` denote the
encoded/decoded coordinates, width and height.
During Box Decoding, two modes for broadcast are supported. Say target box has
shape [N, M, 4], and the shape of prior box can be [N, 4] or [M, 4]. Then prior
box will broadcast to target box along the assigned axis.
)DOC"
);
}
};
}
// namespace operators
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
DECLARE_INFER_SHAPE_FUNCTOR
(
box_coder
,
BoxCoderInferShapeFunctor
,
PD_INFER_META
(
phi
::
BoxCoderInferMeta
));
REGISTER_OPERATOR
(
box_coder
,
ops
::
BoxCoderOp
,
ops
::
BoxCoderOpMaker
,
paddle
::
framework
::
EmptyGradOpMaker
<
paddle
::
framework
::
OpDesc
>
,
paddle
::
framework
::
EmptyGradOpMaker
<
paddle
::
imperative
::
OpBase
>
,
BoxCoderInferShapeFunctor
);
paddle/phi/api/yaml/legacy_ops.yaml
浏览文件 @
ed040a17
...
@@ -139,15 +139,6 @@
...
@@ -139,15 +139,6 @@
func
:
bincount
func
:
bincount
optional
:
weights
optional
:
weights
-
op
:
box_coder
args
:
(Tensor prior_box, Tensor prior_box_var, Tensor target_box, str code_type, bool box_normalized, int axis, float[] variance)
output
:
Tensor(output_box)
infer_meta
:
func
:
BoxCoderInferMeta
kernel
:
func
:
box_coder
optional
:
prior_box_var
-
op
:
cast
-
op
:
cast
args
:
(Tensor x, DataType dtype)
args
:
(Tensor x, DataType dtype)
output
:
Tensor
output
:
Tensor
...
...
paddle/phi/api/yaml/op_compat.yaml
浏览文件 @
ed040a17
...
@@ -343,6 +343,12 @@
...
@@ -343,6 +343,12 @@
outputs
:
outputs
:
out
:
Out
out
:
Out
-
op
:
box_coder
inputs
:
{
prior_box
:
PriorBox
,
prior_box_var
:
PriorBoxVar
,
target_box
:
TargetBox
}
outputs
:
output_box
:
OutputBox
-
op
:
broadcast_tensors
-
op
:
broadcast_tensors
backward
:
broadcast_tensors_grad
backward
:
broadcast_tensors_grad
inputs
:
inputs
:
...
...
paddle/phi/api/yaml/ops.yaml
浏览文件 @
ed040a17
...
@@ -329,6 +329,15 @@
...
@@ -329,6 +329,15 @@
func
:
bmm
func
:
bmm
backward
:
bmm_grad
backward
:
bmm_grad
-
op
:
box_coder
args
:
(Tensor prior_box, Tensor prior_box_var, Tensor target_box, str code_type = "encode_center_size", bool box_normalized =
true
, int axis = 0, float[] variance = {})
output
:
Tensor(output_box)
infer_meta
:
func
:
BoxCoderInferMeta
kernel
:
func
:
box_coder
optional
:
prior_box_var
-
op
:
broadcast_tensors
-
op
:
broadcast_tensors
args
:
(Tensor[] input)
args
:
(Tensor[] input)
output
:
Tensor[]{input.size()}
output
:
Tensor[]{input.size()}
...
...
paddle/phi/ops/compat/box_coder_sig.cc
已删除
100644 → 0
浏览文件 @
652d100d
// 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
BoxCoderOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
)
{
return
KernelSignature
(
"box_coder"
,
{
"PriorBox"
,
"PriorBoxVar"
,
"TargetBox"
},
{
"code_type"
,
"box_normalized"
,
"axis"
,
"variance"
},
{
"OutputBox"
});
}
}
// namespace phi
PD_REGISTER_ARG_MAPPING_FN
(
box_coder
,
phi
::
BoxCoderOpArgumentMapping
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录