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