• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020 Huawei Technologies Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef MINDSPORE_LITE_INCLUDE_TRAIN_ACCURACY_METRICS_H_
17 #define MINDSPORE_LITE_INCLUDE_TRAIN_ACCURACY_METRICS_H_
18 #include <vector>
19 #include "include/train/metrics.h"
20 
21 using mindspore::session::Metrics;
22 
23 namespace mindspore {
24 namespace lite {
25 
26 constexpr int METRICS_CLASSIFICATION = 0;
27 constexpr int METRICS_MULTILABEL = 1;
28 
29 class AccuracyMetrics : public Metrics {
30  public:
31   explicit AccuracyMetrics(int accuracy_metrics = METRICS_CLASSIFICATION, const std::vector<int> &input_indexes = {1},
32                            const std::vector<int> &output_indexes = {0});
33   virtual ~AccuracyMetrics() = default;
Clear()34   void Clear() override { total_accuracy_ = total_steps_ = 0.0; }
35   float Eval() override;
36   void Update(std::vector<lite::Tensor *> inputs, std::vector<lite::Tensor *> outputs) override;
37 
38  protected:
39   int accuracy_metrics_ = METRICS_CLASSIFICATION;
40   std::vector<int> input_indexes_ = {1};
41   std::vector<int> output_indexes_ = {0};
42   float total_accuracy_ = 0.0;
43   float total_steps_ = 0.0;
44   friend class ClassificationTrainAccuracyMonitor;
45 };
46 
47 }  // namespace lite
48 }  // namespace mindspore
49 #endif  // MINDSPORE_LITE_INCLUDE_TRAIN_ACCURACY_METRICS_H_
50