TensorFlow Lite: Models for Mobile and Edge Devices

Deep Learning with Keras and TensorFlow 10 min min read Updated: Nov 16, 2026 Advanced
TensorFlow Lite: Models for Mobile and Edge Devices
Advanced Topic 2 of 7

Why TensorFlow Lite?

Phones, tablets, Raspberry Pi boards and tiny sensors have limited memory and battery. TensorFlow Lite (TFLite) shrinks a model and runs it efficiently on these devices, often without any internet connection.

Step 1: Convert

python import tensorflow as tf import keras model = keras.models.load_model("digit_model.keras") converter = tf.lite.TFLiteConverter.from_keras_model(model) tflite_model = converter.convert() with open("digits.tflite", "wb") as f: f.write(tflite_model) print("Size (KB):", len(tflite_model) / 1024)

Step 2: Quantization (Make It Smaller)

Quantization stores weights with fewer bits. Dynamic range quantization is the easiest version and usually makes the file about four times smaller.

python converter = tf.lite.TFLiteConverter.from_keras_model(model) converter.optimizations = [tf.lite.Optimize.DEFAULT] small_model = converter.convert() print("Quantized size (KB):", len(small_model) / 1024)
MethodResult
No optimizationLargest, original accuracy
Dynamic range quantizationAbout 4x smaller, small accuracy change
Float16 quantizationAbout 2x smaller, good for GPUs
Full integer quantizationSmallest and fastest, needs sample data

Step 3: Run the TFLite Model in Python

python import numpy as np interpreter = tf.lite.Interpreter(model_path="digits.tflite") interpreter.allocate_tensors() inp = interpreter.get_input_details()[0] out = interpreter.get_output_details()[0] (_, _), (x_test, y_test) = keras.datasets.mnist.load_data() sample = (x_test[0:1] / 255.0).astype(np.float32) interpreter.set_tensor(inp["index"], sample) interpreter.invoke() probs = interpreter.get_tensor(out["index"]) print("Predicted:", probs.argmax(), "Real:", y_test[0])
Check accuracy: After quantization, always test the TFLite model on your test set and compare with the original. A tiny drop is normal. A big drop means you should try another quantization method.

Using It on a Phone

  • Android: add the .tflite file to the app and use the TensorFlow Lite or LiteRT library
  • iOS: use the TensorFlow Lite Swift or Objective-C library
  • Web and embedded: other runtimes can load the same file

Google's mobile runtime is now branded LiteRT in newer documentation, and it continues to run .tflite models. Check the official documentation for the current package names before you start an app.

Design Tips for Mobile Models

  • Start from MobileNet or EfficientNet-Lite style backbones
  • Use smaller input sizes, such as 160 x 160
  • Measure speed on the real device, not only on your laptop

Conclusion

TFLite turns heavy models into small ones that run on-device, which keeps data private and works offline.

Quick Summary: Convert with TFLiteConverter, quantize with Optimize.DEFAULT and run with the Interpreter.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators