tf.lite.TFLiteConverter was updated between TensorFlow 1.X and 2.0. This
document explains the differences between the 1.X and 2.0 versions of the
converter, and provides information about how to use the 1.X version if
The following section summarizes the changes in the Python API from 1.X to 2.0. If any of the changes raise concerns, please file a GitHub issue.
Formats supported by
The 2.0 version of the converter supports SavedModel and Keras model files
generated in both 1.X and 2.0. However, the conversion process no longer
supports "frozen graph"
GraphDef files generated in 1.X.
Converting frozen graphs
Users who want to convert frozen graph
GraphDef files (
.pb files) to
TensorFlow Lite should use
The following snippet shows a frozen graph file being converted:
# 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 = 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 attributes and methods associated with
have been removed from
TFLiteConverter in TensorFlow 2.0:
post_training_quantize- Deprecated in the 1.X API
The rewriter function that supports quantization-aware training does not support
models generated by TensorFlow 2.0. Additionally, TensorFlow Lite’s quantization
API is being reworked and streamlined in a direction that supports
quantization-aware training through the Keras API. These attributes will be
removed in the 2.0 API until the new quantization API is launched. Users who
want to convert models generated by the rewriter function can use
target_ops attribute has become an attribute of
TargetSpec and renamed
supported_ops in line with future additions to the optimization framework.
Additionally, the following attributes have been removed:
- Graph visualization - The recommended approach for visualizing a
TensorFlow Lite graph in TensorFlow 2.0 will be to use
Unlike GraphViz, it enables users to visualize the graph after post training
quantization has occurred. The following attributes related to graph
visualization will be removed:
General API changes
The following section explains several significant API changes between TensorFlow 1.X and 2.0.
The following methods that were previously deprecated in 1.X will no longer be exported in 2.0:
lite.constants API was removed in 2.0 in order to decrease duplication
between TensorFlow and TensorFlow Lite. The following list maps the
lite.constant type to the TensorFlow type:
removed due to the deprecation of the
output_format flag in
OpHint API is currently not available in 2.0 due to an incompatibility
with the 2.0 APIs. This API enables conversion of LSTM based models. Support for
LSTMs in 2.0 is being investigated. All related
lite.experimental APIs have
been removed due to this issue.