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_OPTIMIZE_MODIFY_MODEL_INTERFACE_H_ 16 #define TENSORFLOW_LITE_TOOLS_OPTIMIZE_MODIFY_MODEL_INTERFACE_H_ 17 18 #include "tensorflow/lite/model.h" 19 #include "tensorflow/lite/schema/schema_generated.h" 20 21 namespace tflite { 22 namespace optimize { 23 24 // Changes the interface of a quantized model. This method allows the users to 25 // replace float interface with other types. Currently only int8, int16 and 26 // uint8 are supported. 27 // 28 // This method populates the builder with the new model. 29 // 30 // Note: This is a private API, subject to change. 31 TfLiteStatus ModifyModelInterface(flatbuffers::FlatBufferBuilder* builder, 32 ModelT* model, const TensorType& input_type, 33 const TensorType& output_type); 34 35 // Same as above but allows input file path and output file path. 36 // 37 // Note: This is a private API, subject to change. 38 TfLiteStatus ModifyModelInterface(const string& input_file, 39 const string& output_file, 40 const TensorType& input_type, 41 const TensorType& output_type); 42 43 // Adds uint8 quantize ops for specified inputs and uint8 dequantize ops for 44 // specified outputs for a float model. The scale and zero point of uint8 45 // tensors are provided through quant_params. 46 // - input_quant_params has a map between tensor name and the 47 // <scale and zero_point> pair for inputs. 48 // - output_quant_params has a map between tensor name and the 49 // <scale and zero_point> pair for inputs. 50 // For the inputs/output tensors for the model, if its quantization parameters 51 // are not provided, that tensor is not affected. 52 // 53 // Note: This is a private API, subject to change. 54 TfLiteStatus Uint8QuantizeModelInputsOutputs( 55 flatbuffers::FlatBufferBuilder* builder, const Model* input_model, 56 const std::unordered_map<string, std::pair<float, int32_t>>& 57 input_quant_params, 58 const std::unordered_map<string, std::pair<float, int32_t>>& 59 output_quant_params); 60 61 } // namespace optimize 62 } // namespace tflite 63 64 #endif // TENSORFLOW_LITE_TOOLS_OPTIMIZE_MODIFY_MODEL_INTERFACE_H_ 65