tf.lite.TFLiteConverter Python API was updated between TensorFlow 1.x and
2.x. This document explains the differences between the two versions, and
provides information about how to use the 1.x version if required.
If any of the changes raise concerns, please file a GitHub Issue.
SavedModel and Keras
tf.lite.TFLiteConverter API supports SavedModel and Keras HDF5 files
generated in both TensorFlow 1.x and 2.x.
tf.compat.v1.lite.TFLiteConverter API supports frozen graph models
generated in TensorFlow 1.x, as shown below:
import tensorflow as tf # Path to the frozen graph file graph_def_file = 'frozen_graph.pb' # A list of the names of the model's input tensors input_arrays = ['input_name'] # A list of the names of the model's output tensors output_arrays = ['output_name'] # Load and convert the frozen graph converter = tf.compat.v1.lite.TFLiteConverter.from_frozen_graph( graph_def_file, input_arrays, output_arrays) tflite_model = converter.convert() # Write the converted model to disk open("converted_model.tflite", "wb").write(tflite_model)
The following 1.x attribute has been renamed in 2.x.
target_opshas been renamed to
target_spec.supported_ops- In 2.x, in line with future additions to the optimization framework, it has become an attribute of
TargetSpecand has been renamed to
The following 1.x attributes have been removed in 2.x.
- Quantization - In 2.x,
quantize aware training
is supported through the Keras API and
post training quantization
uses fewer streamlined converter flags. Thus, the following attributes and
methods related to quantization have been removed:
- Visualization - In 2.x, the recommended approach for visualizing a
TensorFlow Lite graph is to use
. Unlike GraphViz, it enables users to visualize the graph after post
training quantization has occurred. Thus, the following attributes related
to graph visualization have been removed:
- Frozen graph - In 2.x, the frozen graph model format has been removed.
Thus, the following attribute related to frozen graphs has been removed:
The following section explains several significant features in 1.x that have been removed in 2.x.
The following methods were deprecated in 1.x and have been removed in 2.x:
lite.constants API was removed in 2.x in order to decrease duplication
between TensorFlow and TensorFlow Lite. The following list maps the
lite.constant type to the TensorFlow type:
Additionally, the deprecation of the
output_format flag in
led to the removal of the following constants:
OpHint API is currently unsupported due to an incompatibility with the 2.x
APIs. This API enables conversion of LSTM based models. Support for LSTMs in 2.x
is being investigated. All related
lite.experimental APIs have been removed
due to this issue.