1 /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 #ifndef TENSORFLOW_LITE_TOOLS_EVALUATION_EVALUATION_STAGE_H_ 16 #define TENSORFLOW_LITE_TOOLS_EVALUATION_EVALUATION_STAGE_H_ 17 18 #include "tensorflow/lite/c/common.h" 19 #include "tensorflow/lite/tools/evaluation/proto/evaluation_config.pb.h" 20 21 namespace tflite { 22 namespace evaluation { 23 24 // Superclass for a single stage of an EvaluationPipeline. 25 // Defines basic skeleton for sub-classes to implement. 26 // 27 // Ideally EvaluationStages should obtain access to initializer/input objects 28 // via Get/Set methods on pointers, and not take ownership unless necessary. 29 class EvaluationStage { 30 public: 31 // Initializes an EvaluationStage, including verifying the 32 // EvaluationStageConfig. Returns kTfLiteError if initialization failed, 33 // kTfLiteOk otherwise. 34 // 35 // Sub-classes are responsible for ensuring required class members are defined 36 // via Get/Set methods. 37 virtual TfLiteStatus Init() = 0; 38 39 // An individual run of the EvaluationStage. This is where the task to be 40 // evaluated takes place. Returns kTfLiteError if there was a failure, 41 // kTfLiteOk otherwise. 42 // 43 // Sub-classes are responsible for ensuring they have access to required 44 // inputs via Get/Set methods. 45 virtual TfLiteStatus Run() = 0; 46 47 // Returns the latest metrics based on all Run() calls made so far. 48 virtual EvaluationStageMetrics LatestMetrics() = 0; 49 50 virtual ~EvaluationStage() = default; 51 52 protected: 53 // Constructs an EvaluationStage. 54 // Each subclass constructor must invoke this constructor. EvaluationStage(const EvaluationStageConfig & config)55 explicit EvaluationStage(const EvaluationStageConfig& config) 56 : config_(config) {} 57 58 EvaluationStageConfig config_; 59 }; 60 61 } // namespace evaluation 62 } // namespace tflite 63 64 #endif // TENSORFLOW_LITE_TOOLS_EVALUATION_EVALUATION_STAGE_H_ 65