From 587f66ee7b388925664d14327c925036734cc4d4 Mon Sep 17 00:00:00 2001 From: huangjiyi <43315610+huangjiyi@users.noreply.github.com> Date: Mon, 5 Jun 2023 10:56:36 +0800 Subject: [PATCH] Support code generation for op multiclass_nms3 (#54272) * update * update eager_gen * update * rm intermediate --- .../generator/eager_gen.py | 3 ++ .../operators/detection/multiclass_nms_op.cc | 41 ------------------- paddle/phi/api/yaml/legacy_ops.yaml | 9 ---- paddle/phi/api/yaml/op_compat.yaml | 6 +++ paddle/phi/api/yaml/ops.yaml | 10 +++++ paddle/phi/ops/compat/multiclass_nms3_sig.cc | 36 ---------------- 6 files changed, 19 insertions(+), 86 deletions(-) delete mode 100644 paddle/phi/ops/compat/multiclass_nms3_sig.cc diff --git a/paddle/fluid/eager/auto_code_generator/generator/eager_gen.py b/paddle/fluid/eager/auto_code_generator/generator/eager_gen.py index ec765cd170e..facfd3b8994 100644 --- a/paddle/fluid/eager/auto_code_generator/generator/eager_gen.py +++ b/paddle/fluid/eager/auto_code_generator/generator/eager_gen.py @@ -1469,9 +1469,12 @@ class DygraphForwardFunctionGenerator(DygraphFunctionGeneratorBase): # Get return type list & outputs returns_type_list = ["" for i in range(num_outputs)] returns_list = ["" for i in range(num_outputs)] + num_visited_intermediate_outputs = 0 for name, (rtype, pos) in forward_outputs_position_map.items(): if name in intermediate_outputs: + num_visited_intermediate_outputs += 1 continue + pos -= num_visited_intermediate_outputs returns_list[pos] = f"{name}" if IsPlainTensorType(rtype): diff --git a/paddle/fluid/operators/detection/multiclass_nms_op.cc b/paddle/fluid/operators/detection/multiclass_nms_op.cc index 7c02f37fa3e..c2a967fff9f 100644 --- a/paddle/fluid/operators/detection/multiclass_nms_op.cc +++ b/paddle/fluid/operators/detection/multiclass_nms_op.cc @@ -607,45 +607,12 @@ class MultiClassNMS2OpMaker : public MultiClassNMSOpMaker { } }; -class MultiClassNMS3Op : public MultiClassNMS2Op { - public: - MultiClassNMS3Op(const std::string& type, - const framework::VariableNameMap& inputs, - const framework::VariableNameMap& outputs, - const framework::AttributeMap& attrs) - : MultiClassNMS2Op(type, inputs, outputs, attrs) {} - - protected: - phi::KernelKey GetExpectedKernelType( - const framework::ExecutionContext& ctx) const override { - return phi::KernelKey( - OperatorWithKernel::IndicateVarDataType(ctx, "Scores"), ctx.GetPlace()); - } -}; - -class MultiClassNMS3OpMaker : public MultiClassNMS2OpMaker { - public: - void Make() override { - MultiClassNMS2OpMaker::Make(); - AddInput("RoisNum", - "(Tensor) The number of RoIs in shape (B)," - "B is the number of images") - .AsDispensable(); - AddOutput("NmsRoisNum", "(Tensor), The number of NMS RoIs in each image") - .AsDispensable(); - } -}; - template class MultiClassNMS2Kernel : public MultiClassNMSKernel {}; } // namespace operators } // namespace paddle -DECLARE_INFER_SHAPE_FUNCTOR(multiclass_nms3, - MultiClassNMSShapeFunctor, - PD_INFER_META(phi::MultiClassNMSInferMeta)); - namespace ops = paddle::operators; REGISTER_OPERATOR( multiclass_nms, @@ -668,11 +635,3 @@ PD_REGISTER_STRUCT_KERNEL(multiclass_nms2, ops::MultiClassNMS2Kernel, float, double) {} - -REGISTER_OPERATOR( - multiclass_nms3, - ops::MultiClassNMS3Op, - ops::MultiClassNMS3OpMaker, - paddle::framework::EmptyGradOpMaker, - paddle::framework::EmptyGradOpMaker, - MultiClassNMSShapeFunctor); diff --git a/paddle/phi/api/yaml/legacy_ops.yaml b/paddle/phi/api/yaml/legacy_ops.yaml index 532e445a1a7..01adff8b5d5 100755 --- a/paddle/phi/api/yaml/legacy_ops.yaml +++ b/paddle/phi/api/yaml/legacy_ops.yaml @@ -666,15 +666,6 @@ func : mish backward : mish_grad -- op : multiclass_nms3 - args : (Tensor bboxes, Tensor scores, Tensor rois_num, float score_threshold, int nms_top_k, int keep_top_k, float nms_threshold=0.3, bool normalized=true, float nms_eta=1.0, int background_label=0) - output : Tensor(out), Tensor(index), Tensor(nms_rois_num) - infer_meta : - func : MultiClassNMSInferMeta - kernel : - func : multiclass_nms3 - optional : rois_num - - op : multiply args : (Tensor x, Tensor y) output : Tensor diff --git a/paddle/phi/api/yaml/op_compat.yaml b/paddle/phi/api/yaml/op_compat.yaml index 9f2aa2d20be..3e70e296607 100755 --- a/paddle/phi/api/yaml/op_compat.yaml +++ b/paddle/phi/api/yaml/op_compat.yaml @@ -1702,6 +1702,12 @@ out : Out drop_empty_grad : [x_grad] +- op : multiclass_nms3 + inputs : + {bboxes : BBoxes, scores : Scores, rois_num : RoisNum} + outputs : + {out : Out, index : Index, nms_rois_num : NmsRoisNum} + - op : multinomial inputs : {x : X} diff --git a/paddle/phi/api/yaml/ops.yaml b/paddle/phi/api/yaml/ops.yaml index 043527bbdef..ffbd8bcc034 100644 --- a/paddle/phi/api/yaml/ops.yaml +++ b/paddle/phi/api/yaml/ops.yaml @@ -1548,6 +1548,16 @@ func : multi_dot backward : multi_dot_grad +- op : multiclass_nms3 + args : (Tensor bboxes, Tensor scores, Tensor rois_num, float score_threshold, int nms_top_k, int keep_top_k, float nms_threshold=0.3, bool normalized=true, float nms_eta=1.0, int background_label=0) + output : Tensor(out), Tensor(index), Tensor(nms_rois_num) + infer_meta : + func : MultiClassNMSInferMeta + kernel : + func : multiclass_nms3 + data_type : scores + optional : rois_num, nms_rois_num + - op : multinomial args : (Tensor x, Scalar(int) num_samples = 1, bool replacement = false) output : Tensor(out) diff --git a/paddle/phi/ops/compat/multiclass_nms3_sig.cc b/paddle/phi/ops/compat/multiclass_nms3_sig.cc deleted file mode 100644 index 68dab33b552..00000000000 --- a/paddle/phi/ops/compat/multiclass_nms3_sig.cc +++ /dev/null @@ -1,36 +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 MultiClassNMS3OpArgumentMapping( - const ArgumentMappingContext& ctx UNUSED) { - return KernelSignature("multiclass_nms3", - {"BBoxes", "Scores", "RoisNum"}, - {"score_threshold", - "nms_top_k", - "keep_top_k", - "nms_threshold", - "normalized", - "nms_eta", - "background_label"}, - {"Out", "Index", "NmsRoisNum"}); -} - -} // namespace phi - -PD_REGISTER_ARG_MAPPING_FN(multiclass_nms3, - phi::MultiClassNMS3OpArgumentMapping); -- GitLab