TF Model Conversion to TF Lite (Part 1)
Explore the process of converting TensorFlow models to the lightweight TensorFlow Lite format. Understand different model input types, and learn how to use the TF Lite converter with methods like from_saved_model and from_keras_model. Gain practical skills in reducing model size for mobile deployment while preserving functionality.
We'll cover the following...
In TF, we build DL models using either Keras or a low-level TF API. These models are big in size and can’t run on resource-constrained mobile and edge devices, but we can convert our TF models to a relatively compact format using TF Lite. Let‘s explore the ways to convert TF models to TF Lite models.
Supported models
TF Lite can convert input models in the following formats:
The SavedModel format: This is the recommended standard format to serialize (save to disk) TF models. It also holds the metadata along with the model architecture and trained weights. Therefore, we don’t require any model-building code to load and use a SavedModel.
Keras model: This is a lightweight format supported by the high-level Keras API. It’s an alternative to the SavedModel format. However, Keras model files might not be compatible with other DL frameworks or APIs.
Models from concrete functions: These are constructed using low-level TF APIs.
We can convert and save the models from Keras and concrete functions to the SavedModel format. ...