diff --git a/paddle/fluid/operators/detection/CMakeLists.txt b/paddle/fluid/operators/detection/CMakeLists.txt index 554c701b11e0f2091db34935000bfdbbcf40ef42..1d990b4466a963f0465734c46b790ae4b93cc2ac 100644 --- a/paddle/fluid/operators/detection/CMakeLists.txt +++ b/paddle/fluid/operators/detection/CMakeLists.txt @@ -34,11 +34,9 @@ detection_library(density_prior_box_op SRCS density_prior_box_op.cc if(WITH_XPU) detection_library(iou_similarity_op SRCS iou_similarity_op.cc iou_similarity_op_xpu.cc) - detection_library(prior_box_op SRCS prior_box_op.cc) else() detection_library(iou_similarity_op SRCS iou_similarity_op.cc iou_similarity_op.cu) - detection_library(prior_box_op SRCS prior_box_op.cc) endif() detection_library(bipartite_match_op SRCS bipartite_match_op.cc) diff --git a/paddle/fluid/operators/detection/density_prior_box_op.cc b/paddle/fluid/operators/detection/density_prior_box_op.cc index 572712e7a539bc62f15c6cf5bcd931810b2142b9..2104aee26e4e2c8f4f5a202585f80035f51c361f 100644 --- a/paddle/fluid/operators/detection/density_prior_box_op.cc +++ b/paddle/fluid/operators/detection/density_prior_box_op.cc @@ -268,3 +268,11 @@ PD_REGISTER_STRUCT_KERNEL(density_prior_box, ops::DensityPriorBoxOpKernel, float, double) {} + +REGISTER_OP_KERNEL(prior_box, + MKLDNN, + ::paddle::platform::CPUPlace, + ops::PriorBoxOpKernel, + ops::PriorBoxOpKernel, + ops::PriorBoxOpKernel, + ops::PriorBoxOpKernel); diff --git a/paddle/fluid/operators/detection/prior_box_op.cc b/paddle/fluid/operators/detection/prior_box_op.cc deleted file mode 100644 index be1e224cd30fe6e2f0efb1d9704a8e853f8ddb99..0000000000000000000000000000000000000000 --- a/paddle/fluid/operators/detection/prior_box_op.cc +++ /dev/null @@ -1,194 +0,0 @@ -/* Copyright (c) 2016 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/fluid/operators/detection/prior_box_op.h" -#include -#include "paddle/fluid/framework/convert_utils.h" -#include "paddle/fluid/framework/infershape_utils.h" -#include "paddle/phi/infermeta/binary.h" - -namespace paddle { -namespace operators { - -class PriorBoxOp : public framework::OperatorWithKernel { - public: - using framework::OperatorWithKernel::OperatorWithKernel; - - protected: - phi::KernelKey GetExpectedKernelType( - const framework::ExecutionContext& ctx) const override { - auto input_input_type = - OperatorWithKernel::IndicateVarDataType(ctx, "Input"); - return phi::KernelKey(input_input_type, ctx.GetPlace()); - } -}; - -class PriorBoxOpMaker : public framework::OpProtoAndCheckerMaker { - public: - void Make() override { - AddInput("Input", - "(Tensor, default Tensor), " - "the input feature data of PriorBoxOp, The layout is NCHW."); - AddInput("Image", - "(Tensor, default Tensor), " - "the input image data of PriorBoxOp, The layout is NCHW."); - AddOutput("Boxes", - "(Tensor, default Tensor), the output prior boxes of " - "PriorBoxOp. The layout is [H, W, num_priors, 4]. " - "H is the height of input, W is the width of input, num_priors " - "is the box count of each position."); - AddOutput("Variances", - "(Tensor, default Tensor), the expanded variances of " - "PriorBoxOp. The layout is [H, W, num_priors, 4]. " - "H is the height of input, W is the width of input, num_priors " - "is the box count of each position."); - - AddAttr>("min_sizes", - "(vector) List of min sizes " - "of generated prior boxes.") - .AddCustomChecker([](const std::vector& min_sizes) { - PADDLE_ENFORCE_GT( - min_sizes.size(), - 0, - platform::errors::InvalidArgument("Size of min_sizes must be " - "at least 1.")); - for (size_t i = 0; i < min_sizes.size(); ++i) { - PADDLE_ENFORCE_GT(min_sizes[i], - 0.0, - platform::errors::OutOfRange( - "min_sizes[%d] must be larger " - "than 0. But received: min_sizes[%d] is %f.", - i, - i, - min_sizes[i])); - } - }); - AddAttr>( - "max_sizes", - "(vector) List of max sizes of generated prior boxes.") - .SetDefault(std::vector{}); - AddAttr>( - "aspect_ratios", - "(vector) List of aspect ratios of generated prior boxes."); - - AddAttr>( - "variances", - "(vector) List of variances to be encoded in prior boxes.") - .AddCustomChecker([](const std::vector& variances) { - PADDLE_ENFORCE_EQ(variances.size(), - 4, - platform::errors::InvalidArgument( - "The length of variance must " - "be 4. But received: variances' length is %d.", - variances.size())); - for (size_t i = 0; i < variances.size(); ++i) { - PADDLE_ENFORCE_GT(variances[i], - 0.0, - platform::errors::OutOfRange( - "variance[%d] must be greater " - "than 0. But received: variance[%d] = %f", - i, - i, - variances[i])); - } - }); - AddAttr("flip", "(bool) Whether to flip aspect ratios.") - .SetDefault(true); - AddAttr("clip", "(bool) Whether to clip out-of-boundary boxes.") - .SetDefault(true); - - AddAttr("step_w", - "Prior boxes step across width, 0.0 for auto calculation.") - .SetDefault(0.0) - .AddCustomChecker([](const float& step_w) { - PADDLE_ENFORCE_GE(step_w, - 0.0, - platform::errors::InvalidArgument( - "step_w should be larger " - "than 0. But received: step_w = %f.", - step_w)); - }); - AddAttr("step_h", - "Prior boxes step across height, 0.0 for auto calculation.") - .SetDefault(0.0) - .AddCustomChecker([](const float& step_h) { - PADDLE_ENFORCE_GE(step_h, - 0.0, - platform::errors::InvalidArgument( - "step_h should be larger " - "than 0. But received: step_h = %f.", - step_h)); - }); - - AddAttr("offset", - "(float) " - "Prior boxes center offset.") - .SetDefault(0.5); - AddAttr( - "min_max_aspect_ratios_order", - "(bool) If set True, the output prior box is in order of" - "[min, max, aspect_ratios], which is consistent with Caffe." - "Please note, this order affects the weights order of convolution layer" - "followed by and does not affect the final detection results.") - .SetDefault(false); - AddAttr("use_mkldnn", - "(bool, default false) Only used in mkldnn kernel") - .SetDefault(false); - AddAttr( - "use_quantizer", - "(bool, default false) " - "This parameter is no longer used. Use 'mkldnn_data_type' instead.") - .SetDefault(false); - AddAttr( - "mkldnn_data_type", - "(string, default \"float32\"). Data type of mkldnn kernel") - .SetDefault("float32") - .InEnum({"float32", "int8", "bfloat16"}); - AddComment(R"DOC( -Prior box operator -Generate prior boxes for SSD(Single Shot MultiBox Detector) algorithm. -Each position of the input produce N prior boxes, N is determined by - the count of min_sizes, max_sizes and aspect_ratios, The size of the - box is in range(min_size, max_size) interval, which is generated in - sequence according to the aspect_ratios. - -Please get more information from the following papers: -https://arxiv.org/abs/1512.02325. -)DOC"); - } -}; - -} // namespace operators -} // namespace paddle - -DECLARE_INFER_SHAPE_FUNCTOR(prior_box, - PriorBoxInferShapeFunctor, - PD_INFER_META(phi::PriorBoxInferMeta)); - -namespace ops = paddle::operators; -REGISTER_OPERATOR( - prior_box, - ops::PriorBoxOp, - ops::PriorBoxOpMaker, - paddle::framework::EmptyGradOpMaker, - paddle::framework::EmptyGradOpMaker, - PriorBoxInferShapeFunctor); - -REGISTER_OP_KERNEL(prior_box, - MKLDNN, - ::paddle::platform::CPUPlace, - ops::PriorBoxOpKernel, - ops::PriorBoxOpKernel, - ops::PriorBoxOpKernel, - ops::PriorBoxOpKernel); diff --git a/paddle/phi/api/yaml/legacy_ops.yaml b/paddle/phi/api/yaml/legacy_ops.yaml index b817946691d2e5a80ed46a1b7d0d84a89cdd013f..25a821dc1a705e57117a0132e06badfeaef9d5fc 100755 --- a/paddle/phi/api/yaml/legacy_ops.yaml +++ b/paddle/phi/api/yaml/legacy_ops.yaml @@ -727,14 +727,6 @@ param : [x, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm] backward : pool3d_grad -- op : prior_box - args : (Tensor input, Tensor image, float[] min_sizes, float[] max_sizes = {}, float[] aspect_ratios = {}, float[] variances = {}, bool flip=true, bool clip=true, float step_w=0.0, float step_h=0.0, float offset=0.5, bool min_max_aspect_ratios_order=false) - output : Tensor(out), Tensor(var) - infer_meta : - func : PriorBoxInferMeta - kernel : - func : prior_box - - op : prod args : (Tensor x, IntArray dims, bool keep_dim, bool reduce_all) output : Tensor diff --git a/paddle/phi/api/yaml/op_compat.yaml b/paddle/phi/api/yaml/op_compat.yaml index 75ad141814917168f473e93b5651279022620ffc..04b372d391726b063063e43058b73e6b382f0d5f 100755 --- a/paddle/phi/api/yaml/op_compat.yaml +++ b/paddle/phi/api/yaml/op_compat.yaml @@ -1984,6 +1984,14 @@ extra : attrs : [bool use_mkldnn = false, str mkldnn_data_type = "float32", bool is_test = false] +- op : prior_box + inputs : + {input: Input, image: Image} + outputs : + {out: Boxes, var: Variances} + extra : + attrs : [bool use_mkldnn = false, bool use_quantizer = false, str mkldnn_data_type = "float32"] + - op : prod (reduce_prod) backward : prod_grad (reduce_prod_grad) inputs: diff --git a/paddle/phi/api/yaml/ops.yaml b/paddle/phi/api/yaml/ops.yaml index 130cd3785a16ffeb0aec2bee7039f8ed657b9ebd..6e6fa098e1a37bbb9b13ee19a589261e635d482b 100644 --- a/paddle/phi/api/yaml/ops.yaml +++ b/paddle/phi/api/yaml/ops.yaml @@ -1803,6 +1803,15 @@ data_type : x backward : prelu_grad +- op : prior_box + args : (Tensor input, Tensor image, float[] min_sizes, float[] max_sizes = {}, float[] aspect_ratios = {}, float[] variances = {}, bool flip=true, bool clip=true, float step_w=0.0, float step_h=0.0, float offset=0.5, bool min_max_aspect_ratios_order=false) + output : Tensor(out), Tensor(var) + infer_meta : + func : PriorBoxInferMeta + kernel : + func : prior_box + data_type : input + - op : put_along_axis args : (Tensor arr, Tensor indices, Tensor values, int axis, str reduce = "assign") output : Tensor(out) diff --git a/paddle/phi/ops/compat/prior_box_sig.cc b/paddle/phi/ops/compat/prior_box_sig.cc deleted file mode 100644 index a8860246ca825a382a3ca75f9889a415919a2d10..0000000000000000000000000000000000000000 --- a/paddle/phi/ops/compat/prior_box_sig.cc +++ /dev/null @@ -1,38 +0,0 @@ -// 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 PriorBoxOpArgumentMapping( - const ArgumentMappingContext& ctx UNUSED) { - return KernelSignature("prior_box", - {"Input", "Image"}, - {"min_sizes", - "max_sizes", - "aspect_ratios", - "variances", - "flip", - "clip", - "step_w", - "step_h", - "offset", - "min_max_aspect_ratios_order"}, - {"Boxes", "Variances"}); -} - -} // namespace phi - -PD_REGISTER_ARG_MAPPING_FN(prior_box, phi::PriorBoxOpArgumentMapping);