This page shows how you can start running TensorFlow Lite models with Python in just a few minutes. All you need is a TensorFlow model converted to TensorFlow Lite. (If you don't have a model converted yet, you can experiment using the model provided with the example linked below.)
Install just the TensorFlow Lite interpreter
To quickly start executing TensorFlow Lite models with Python, you can install just the TensorFlow Lite interpreter, instead of all TensorFlow packages.
This interpreter-only package is a fraction the size of the full TensorFlow
package and includes the bare minimum code required to run inferences with
TensorFlow Lite—it includes only the
tf.lite.Interpreter Python class.
This small package is ideal when all you want to do is execute
and avoid wasting disk space with the large TensorFlow library.
To install just the interpreter, download the appropriate Python wheel for your
system from the following table, and then install it with the
For example, if you're setting up a Raspberry Pi (using Raspbian Buster, which
has Python 3.7), install the Python wheel as follows (after you click to
.whl file below):
pip3 install tflite_runtime-1.14.0-cp37-cp37m-linux_armv7l.whl
Run an inference using tflite_runtime
To distinguish this interpreter-only package from the full TensorFlow package
(allowing both to be installed, if you choose), the Python module provided in
the above wheel is named
So instead of importing
Interpreter from the
tensorflow module, you need to
import it from
For example, after you install the package above, copy and run the
file. It will (probably) fail because you don't have the
installed. To fix it, simply edit this line of the file:
from tensorflow.lite.python.interpreter import Interpreter
So it instead reads:
from tflite_runtime import Interpreter
label_image.py again. That's it! You're now executing TensorFlow Lite
For more details about the
Interpreter API, read Load and run a model
To convert other TensorFlow models to TensorFlow Lite, read about the the TensorFlow Lite Converter.