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_QUANTIZE_WEIGHTS_H_ 16 #define TENSORFLOW_LITE_TOOLS_OPTIMIZE_QUANTIZE_WEIGHTS_H_ 17 18 #include <memory> 19 #include "flatbuffers/flexbuffers.h" 20 #include "tensorflow/lite/context.h" 21 #include "tensorflow/lite/model.h" 22 #include "tensorflow/lite/schema/schema_generated.h" 23 24 namespace tflite { 25 namespace optimize { 26 27 // Quantizes input_model and populates the provided builder with the new model. 28 // By default only weights tensors weight more than 1024 elements will be 29 // quantized. 30 // 31 // A tflite::Model can be obtained from the builder with: 32 // const uint8_t* buffer = builder->GetBufferPointer(); 33 // tflite::Model* model = GetModel(buffer); 34 TfLiteStatus QuantizeWeights(flatbuffers::FlatBufferBuilder* builder, 35 const Model* input_model); 36 37 // Same as above, but only weights with greater than or equal 38 // weights_min_num_elements elements will be quantized. 39 TfLiteStatus QuantizeWeights(flatbuffers::FlatBufferBuilder* builder, 40 const Model* input_model, 41 uint64_t weights_min_num_elements); 42 43 namespace internal { 44 // If use_hybrid_evaluation is false, will disable using hybrid eval for 45 // operations that support it. 46 // 47 // We use this internal QuantizeWeights call to test models with hybrid 48 // evaluation disabled. 49 TfLiteStatus QuantizeWeights(flatbuffers::FlatBufferBuilder* builder, 50 const Model* input_model, 51 uint64_t weights_min_num_elements, 52 bool use_hybrid_evaluation); 53 } // namespace internal 54 55 } // namespace optimize 56 } // namespace tflite 57 58 #endif // TENSORFLOW_LITE_TOOLS_OPTIMIZE_QUANTIZE_WEIGHTS_H_ 59