xref: /aosp_15_r20/external/tensorflow/tensorflow/lite/tools/evaluation/tasks/task_executor.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1 /* Copyright 2020 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_TASKS_TASK_EXECUTOR_H_
16 #define TENSORFLOW_LITE_TOOLS_EVALUATION_TASKS_TASK_EXECUTOR_H_
17 
18 #include <optional>
19 
20 #include "absl/types/optional.h"
21 #include "tensorflow/lite/tools/command_line_flags.h"
22 #include "tensorflow/lite/tools/evaluation/evaluation_delegate_provider.h"
23 #include "tensorflow/lite/tools/evaluation/proto/evaluation_config.pb.h"
24 
25 namespace tflite {
26 namespace evaluation {
27 // A common task execution API to avoid boilerpolate code in defining the main
28 // function.
29 class TaskExecutor {
30  public:
~TaskExecutor()31   virtual ~TaskExecutor() {}
32 
33   // If the run is successful, the latest metrics will be returned.
34   std::optional<EvaluationStageMetrics> Run(int* argc, char* argv[]);
35 
36  protected:
37   // Returns a list of commandline flags that this task defines.
38   virtual std::vector<Flag> GetFlags() = 0;
39 
40   virtual std::optional<EvaluationStageMetrics> RunImpl() = 0;
41 
42   DelegateProviders delegate_providers_;
43 };
44 
45 // Just a declaration. In order to avoid the boilerpolate main-function code,
46 // every evaluation task should define this function.
47 std::unique_ptr<TaskExecutor> CreateTaskExecutor();
48 }  // namespace evaluation
49 }  // namespace tflite
50 
51 #endif  // TENSORFLOW_LITE_TOOLS_EVALUATION_TASKS_TASK_EXECUTOR_H_
52