• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_IDENTITY_STAGE_H_
16 #define TENSORFLOW_LITE_TOOLS_EVALUATION_IDENTITY_STAGE_H_
17 
18 #include "absl/container/flat_hash_map.h"
19 #include "tensorflow/lite/tools/evaluation/evaluation_stage.h"
20 #include "tensorflow/lite/tools/evaluation/proto/evaluation_config.pb.h"
21 
22 namespace tflite {
23 namespace evaluation {
24 
25 // Simple EvaluationStage that passes INPUT_VALUE to OUTPUT_VALUE if the former
26 // is non-zero, DEFAULT_VALUE otherwise. Primarily used for tests.
27 // Initializer TAGs (Object Class): DEFAULT_VALUE (float)
28 // Input TAGs (Object Class): INPUT_VALUE (float)
29 // Output TAGs (Object Class): OUTPUT_VALUE (float)
30 class IdentityStage : public EvaluationStage {
31  public:
IdentityStage(const EvaluationStageConfig & config)32   explicit IdentityStage(const EvaluationStageConfig& config)
33       : EvaluationStage(config) {}
34 
35   bool Run(absl::flat_hash_map<std::string, void*>& object_map) override;
36 
37   EvaluationStageMetrics LatestMetrics() override;
38 
~IdentityStage()39   ~IdentityStage() {}
40 
41  protected:
42   bool DoInit(absl::flat_hash_map<std::string, void*>& object_map) override;
43 
GetInitializerTags()44   std::vector<std::string> GetInitializerTags() override {
45     return {kDefaultValueTag};
46   }
GetInputTags()47   std::vector<std::string> GetInputTags() override { return {kInputValueTag}; }
GetOutputTags()48   std::vector<std::string> GetOutputTags() override {
49     return {kOutputValueTag};
50   }
51 
52  private:
53   float default_value_ = 0;
54   float current_value_ = 0;
55   int num_runs_ = 0;
56 
57   static const char kDefaultValueTag[];
58   static const char kInputValueTag[];
59   static const char kOutputValueTag[];
60 };
61 
62 DECLARE_FACTORY(IdentityStage);
63 
64 }  // namespace evaluation
65 }  // namespace tflite
66 
67 #endif  // TENSORFLOW_LITE_TOOLS_EVALUATION_IDENTITY_STAGE_H_
68