Defined in tensorflow/contrib/lite/python/

Builds protocol buffers describing a conversion of a model using TOCO.

Typically this is to convert from TensorFlow GraphDef to TFLite, in which case the default input_format and output_format are sufficient.


  • input_tensors: List of input tensors. Type and shape are computed using foo.get_shape() and foo.dtype.
  • output_tensors: List of output tensors (only .name is used from this).
  • inference_type: Target data type of real-number arrays in the output file. Must be {FLOAT, QUANTIZED_UINT8}. (default FLOAT)
  • inference_input_type: Target data type of real-number input arrays. Allows for a different type for input arrays in the case of quantization. Must be {FLOAT, QUANTIZED_UINT8}. (default inference_type)
  • input_format: Type of data to read Currently must be {TENSORFLOW_GRAPHDEF}. (default TENSORFLOW_GRAPHDEF)
  • output_format: Output file format. Currently must be {TFLITE, GRAPHVIZ_DOT}. (default TFLITE)
  • quantized_input_stats: List of tuples of integers representing the mean and standard deviation. Each tuple maps to the corresponding input tensor. Only need if inference_type is QUANTIZED_UINT8. (default None)
  • default_ranges_stats: Tuple of integers representing (min, max) range values for all arrays without a specified range. Intended for experimenting with quantization via "dummy quantization". (default None)
  • drop_control_dependency: Boolean indicating whether to drop control dependencies silently. This is due to TFLite not supporting control dependencies. (default True)
  • reorder_across_fake_quant: Boolean indicating whether to reorder FakeQuant nodes in unexpected locations. Used when the location of the FakeQuant nodes is preventing graph transformations necessary to convert the graph. Results in a graph that differs from the quantized training graph, potentially causing differing arithmetic behavior. (default False)
  • allow_custom_ops: Boolean indicating whether to allow custom operations. When false any unknown operation is an error. When true, custom ops are created for any op that is unknown. The developer will need to provide these to the TensorFlow Lite runtime with a custom resolver. (default False)
  • change_concat_input_ranges: Boolean to change behavior of min/max ranges for inputs and outputs of the concat operator for quantized models. Changes the ranges of concat operator overlap when true. (default False)
  • quantize_weights: Boolean indicating whether to store weights as quantized weights followed by dequantize operations. Computation is still done in float, but reduces model size (at the cost of accuracy and latency). (default False)
  • dump_graphviz_dir: Full filepath of folder to dump the graphs at various stages of processing GraphViz .dot files. Preferred over --output_format=GRAPHVIZ_DOT in order to keep the requirements of the output file. (default None)
  • dump_graphviz_video: Boolean indicating whether to dump the graph after every graph transformation. (default False)


model_flags, toco_flags: two protocol buffers describing the conversion process.


  • ValueError: If the input tensor type is unknown
  • RuntimeError: If TOCO fails to convert (in which case the runtime error's error text will contain the TOCO error log)