diff --git a/paddle/fluid/operators/metrics/accuracy_op.cc b/paddle/fluid/operators/metrics/accuracy_op.cc deleted file mode 100644 index 25e32b51978437472165a94ed529f5b448a4d11d..0000000000000000000000000000000000000000 --- a/paddle/fluid/operators/metrics/accuracy_op.cc +++ /dev/null @@ -1,77 +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/framework/infershape_utils.h" -#include "paddle/fluid/framework/op_registry.h" -#include "paddle/phi/infermeta/ternary.h" - -namespace paddle { -namespace operators { - -class AccuracyOp : public framework::OperatorWithKernel { - public: - using framework::OperatorWithKernel::OperatorWithKernel; - - protected: - phi::KernelKey GetExpectedKernelType( - const framework::ExecutionContext &ctx) const override { - return phi::KernelKey(OperatorWithKernel::IndicateVarDataType(ctx, "Out"), - ctx.GetPlace()); - } -}; - -class AccuracyOpMaker : public framework::OpProtoAndCheckerMaker { - public: - void Make() override { - // TODO(typhoonzero): support both inference value and indices. - AddInput("Out", "The network output of topk (inferences)"); - AddInput("Indices", "The network output of topk (indices)"); - AddInput("Label", "Label of the training data"); - // TODO(typhoonzero): AddInput("Weight", ... - AddOutput("Accuracy", "The accuracy of current batch"); - AddOutput("Correct", "The correct samples count of current batch"); - AddOutput("Total", "The samples count of current batch"); - - AddComment(R"DOC( -Accuracy Operator. - -It will print accuracy rate for classification. -The accuracy is calculated as follows: - -$$accuracy = \frac{NumOfCorrectPredicts}{NumOfAllSamples}$$ - -Both the input Out and Label can carry the LoD (Level of Details) -information, or not. But the output only shares the LoD information -with the input Out(Inference). - -)DOC"); - } -}; - -} // namespace operators -} // namespace paddle - -// FIXME(typhoonzero): types of T is for infernece data. -// label data is always int. -DECLARE_INFER_SHAPE_FUNCTOR(accuracy, - AccuracyInferShapeFunctor, - PD_INFER_META(phi::AccuracyInferMeta)); -namespace ops = paddle::operators; -REGISTER_OPERATOR( - accuracy, - ops::AccuracyOp, - ops::AccuracyOpMaker, - paddle::framework::EmptyGradOpMaker, - paddle::framework::EmptyGradOpMaker, - AccuracyInferShapeFunctor); diff --git a/paddle/phi/api/yaml/legacy_ops.yaml b/paddle/phi/api/yaml/legacy_ops.yaml index 7484bb50298ac0ce9f76a6279c4b5ddbd87c8001..92cc67bc9da0464fe20afed4a720f292d3fb6098 100755 --- a/paddle/phi/api/yaml/legacy_ops.yaml +++ b/paddle/phi/api/yaml/legacy_ops.yaml @@ -10,15 +10,6 @@ func : abs backward : abs_grad -- op : accuracy - args : (Tensor x, Tensor indices, Tensor label) - output : Tensor(accuracy), Tensor(correct), Tensor(total) - infer_meta : - func : AccuracyInferMeta - kernel : - func : accuracy - data_type : x - - op : adadelta_ args : (Tensor param, Tensor grad, Tensor avg_squared_grad, Tensor avg_squared_update, Tensor master_param, float rho, float epsilon, bool multi_precision) output : Tensor(param_out), Tensor(moment_out), Tensor(inf_norm_out), Tensor(master_param_out) diff --git a/paddle/phi/api/yaml/op_compat.yaml b/paddle/phi/api/yaml/op_compat.yaml index 51b03693f3061205ddca7fd4f750de55653ae5fc..45c87aaca57a873e08819c925da6d27313137da3 100644 --- a/paddle/phi/api/yaml/op_compat.yaml +++ b/paddle/phi/api/yaml/op_compat.yaml @@ -23,6 +23,12 @@ extra : attrs : [bool use_mkldnn = false] +- op : accuracy + inputs : + {x : Out , indices : Indices, label: Label} + outputs : + {accuracy : Accuracy, correct : Correct, total : Total} + - op : acos inputs : x : X diff --git a/paddle/phi/api/yaml/ops.yaml b/paddle/phi/api/yaml/ops.yaml index cf126e8d4d8928f8431d62801de53aed35c4f1e6..473b18dbcc4768004d934de491344cc4f124fdda 100644 --- a/paddle/phi/api/yaml/ops.yaml +++ b/paddle/phi/api/yaml/ops.yaml @@ -5,6 +5,15 @@ # are consistent and correspond one-to-one. It's forbidden that the # operator configured in this yaml file does not have Python API. +- op : accuracy + args : (Tensor x, Tensor indices, Tensor label) + output : Tensor(accuracy), Tensor(correct), Tensor(total) + infer_meta : + func : AccuracyInferMeta + kernel : + func : accuracy + data_type : x + - op : acos args : (Tensor x) output : Tensor