Home | History | Annotate | Download | only in evaluation
      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 #include "tensorflow/lite/tools/evaluation/identity_stage.h"
     16 
     17 #include "tensorflow/lite/tools/evaluation/evaluation_stage.h"
     18 #include "tensorflow/lite/tools/evaluation/proto/evaluation_stages.pb.h"
     19 
     20 namespace tflite {
     21 namespace evaluation {
     22 
     23 bool IdentityStage::DoInit(
     24     absl::flat_hash_map<std::string, void*>& object_map) {
     25   float* default_value;
     26   if (!GetObjectFromTag(kDefaultValueTag, object_map, &default_value)) {
     27     return false;
     28   }
     29   default_value_ = *default_value;
     30   return true;
     31 }
     32 
     33 bool IdentityStage::Run(absl::flat_hash_map<std::string, void*>& object_map) {
     34   float* current_value;
     35   GET_OBJECT(kInputValueTag, object_map, &current_value);
     36   current_value_ = *current_value ? *current_value : default_value_;
     37   ASSIGN_OBJECT(kOutputValueTag, &current_value_, object_map);
     38   ++num_runs_;
     39   return true;
     40 }
     41 
     42 EvaluationStageMetrics IdentityStage::LatestMetrics() {
     43   EvaluationStageMetrics metrics;
     44   metrics.set_num_runs(num_runs_);
     45   return metrics;
     46 }
     47 
     48 const char IdentityStage::kDefaultValueTag[] = "DEFAULT_VALUE";
     49 const char IdentityStage::kInputValueTag[] = "INPUT_VALUE";
     50 const char IdentityStage::kOutputValueTag[] = "OUTPUT_VALUE";
     51 
     52 DEFINE_FACTORY(IdentityStage, IDENTITY);
     53 
     54 }  // namespace evaluation
     55 }  // namespace tflite
     56