Export and convert a file to LiteRT
The following sections describe how to export models in LiteRT format and convert models from other formats to LiteRT.
Export a LiteRT file from a machine learning framework
You can export a model from most machine learning frameworks in LiteRT format.
To export a PyTorch model to LiteRT, refer to Convert PyTorch models to LiteRT on the LiteRT website.
For more information about LiteRT compatibility, refer to Import a model file.
Export TensorFlow files to LiteRT
Exporting files from TensorFlow involves two key file types: SavedModel and Checkpoints.
SavedModel files
TensorFlow saves models in SavedModel files, which contain a complete TensorFlow program, including trained parameters and computation. SavedModels have the .pb file extension. For more information on SavedModels, refer to Using the SavedModel format (TensorFlow documentation).
You can convert TensorFlow models to TFLite format using the TensorFlow Lite Converter (TFLiteConverter).
Checkpoints
Checkpoints (TensorFlow documentation) contain only the model parameters.
Checkpoints in TensorFlow can consist up of two file formats:
- A file to store the graph, with the extension
.ckpt.meta. - A file to store the weights, with the extension
.ckpt.
To convert a checkpoint to LiteRT:
- Restore the model in TensorFlow with both the graph and weights file types.
- If only the
.ckptfile is available, locate the Python code that defines the model and loads the weights. - Convert the restored model using the TensorFlow Lite Converter (TFLiteConverter).
Convert PyTorch files to LiteRT
Use this information to understand how to convert PyTorch files to the LiteRT format.
Model files
PyTorch model files usually have the .pt file extension.
To export a model file to LiteRT, follow these steps:
- Load the model in Python.
- Convert the model as a LiteRT file.
If your .pt file doesn't contain the model graph, you must find the Python code that constructs the model and loads in the weights.
Checkpoints
You can create Checkpoints in PyTorch to save the state of your model at any instance of time. Checkpoint files are usually denoted with the .tar or .pth extension.
To convert a checkpoint file to LiteRT, you must find the Python code that constructs the model and loads in the weights.