tf.contrib.lite.build_toco_convert_protos

tf.contrib.lite.build_toco_convert_protos(
    input_tensors,
    output_tensors,
    inference_type=lite_constants.FLOAT,
    inference_input_type=None,
    input_format=lite_constants.TENSORFLOW_GRAPHDEF,
    input_shapes=None,
    output_format=lite_constants.TFLITE,
    quantized_input_stats=None,
    default_ranges_stats=None,
    drop_control_dependency=True,
    reorder_across_fake_quant=False,
    allow_custom_ops=False,
    change_concat_input_ranges=False,
    post_training_quantize=False,
    dump_graphviz_dir=None,
    dump_graphviz_video=False
)

Defined in tensorflow/contrib/lite/python/convert.py.

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.

Args:

  • 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)
  • input_shapes: Input array shape. It needs to be a list of the same length as input_tensors, or None. (default None)
  • output_format: Output file format. Currently must be {TFLITE, GRAPHVIZ_DOT}. (default TFLITE)
  • quantized_input_stats: List of tuples of floats representing the mean and standard deviation. Each tuple maps to the corresponding input tensor. Only need if inference_input_type is QUANTIZED_UINT8. real_input_value = (quantized_input_value - mean_value) / std_dev_value. (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)
  • post_training_quantize: Boolean indicating whether to quantize the weights of the converted float model. Model size will be reduced and there will be latency improvements (at the cost of accuracy). (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)

Returns:

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

Raises:

  • 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)