1 /* Copyright 2018 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_OPTIMIZE_CALIBRATION_READER_H_ 16 #define TENSORFLOW_LITE_TOOLS_OPTIMIZE_CALIBRATION_READER_H_ 17 18 #include "tensorflow/lite/context.h" 19 #include "tensorflow/lite/model.h" 20 #include "tensorflow/lite/tools/optimize/calibration/calibration_logger.h" 21 22 namespace tflite { 23 namespace optimize { 24 namespace calibration { 25 // Warning: This is not a public API and subject to change. 26 // 27 // Reads calibrator data collected by running the interpreter through 28 // a calibration set. 29 class CalibrationReader { 30 public: 31 struct CalibrationStats { 32 float min; 33 float max; 34 }; CalibrationReader(const Logger * logger)35 explicit CalibrationReader(const Logger* logger) : logger_(logger) {} 36 37 // Gets a map from tensor index to recorded calibration values. 38 virtual TfLiteStatus GetTensorStatsAsMap( 39 absl::flat_hash_map<std::tuple<int, int>, CalibrationStats>* 40 tensor_id_to_stats_map) const; 41 42 // Annotates the tensors in the given model with statistics captured during 43 // calibration. 44 // "update" is a flag: when set to true, the min/max are updated, instead of 45 // being overwritten. 46 virtual TfLiteStatus AddCalibrationToModel(ModelT* model, bool update) const; 47 ~CalibrationReader()48 virtual ~CalibrationReader() {} 49 50 private: 51 const Logger* logger_; 52 }; 53 } // namespace calibration 54 } // namespace optimize 55 } // namespace tflite 56 #endif // TENSORFLOW_LITE_TOOLS_OPTIMIZE_CALIBRATION_READER_H_ 57