1 /* Copyright 2017 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_TOCO_PYTHON_TOCO_PYTHON_API_H_ 16 #define TENSORFLOW_LITE_TOCO_PYTHON_TOCO_PYTHON_API_H_ 17 18 #include <Python.h> 19 20 #include <string> 21 22 namespace toco { 23 24 // Convert a model represented in `input_contents`. `model_flags_proto` 25 // describes model parameters. `toco_flags_proto` describes conversion 26 // parameters (see relevant .protos for more information). Returns a string 27 // representing the contents of the converted model. When extended_return 28 // flag is set to true returns a dictionary that contains string representation 29 // of the converted model and some statistics like arithmetic ops count. 30 // `debug_info_str` contains the `GraphDebugInfo` proto. When 31 // `enable_mlir_converter` is True, use MLIR-based conversion instead of 32 // TOCO conversion. 33 PyObject* TocoConvert(PyObject* model_flags_proto_txt_raw, 34 PyObject* toco_flags_proto_txt_raw, 35 PyObject* input_contents_txt_raw, 36 bool extended_return = false, 37 PyObject* debug_info_txt_raw = nullptr, 38 bool enable_mlir_converter = false); 39 40 // Returns a list of names of all ops potentially supported by tflite. 41 PyObject* TocoGetPotentiallySupportedOps(); 42 43 // Quantize the model with calibration data. Throw errors if `fully_quantize` 44 // is specified by the calibration data are not sufficient to quantize the 45 // model. 46 PyObject* MlirQuantizeModel(PyObject* data, bool disable_per_channel, 47 bool fully_quantize, int inference_type, 48 bool enable_numeric_verify = false); 49 50 // Sparsifies model to encode sparse tensors with proper format. Throws error if 51 // sparsification fails. 52 PyObject* MlirSparsifyModel(PyObject* data); 53 54 // Registers the given custom opdefs to TensorFlow global op registry. 55 PyObject* RegisterCustomOpdefs(PyObject* list); 56 } // namespace toco 57 58 #endif // TENSORFLOW_LITE_TOCO_PYTHON_TOCO_PYTHON_API_H_ 59