Skip to main content
This page covers converting TensorFlow models to quantized TFLite format. Once converted, you run the resulting .tflite file on the NPU using LiteRT.
Looking to run an already-converted model? Skip this page and go directly to Run LiteRT / TFLite models. You only need this page if you have a TensorFlow model that hasn’t been quantized yet.
TensorFlow is an open-source machine learning framework developed by Google that provides tools for building, training, and deploying neural networks. To run TensorFlow models on the NPU of your Dragonwing development board you’ll need to convert your model to a quantized TFLite model. You can then use LiteRT to run the model with full hardware acceleration.

Quantizing and converting a model

TensorFlow models use 32-bit floating point numbers for their weights and activations. The NPU on your development board only supports 8-bit integers, so TensorFlow models must be quantized - converted from floating point to fixed point values. This makes the model smaller and faster to run (and able to run on the NPU), but it has an effect on accuracy. The easiest way to quantize models is using post-training quantization. Here you take an already trained model, then quantize the weights and activations using a representative dataset. This means that there’s no effect in the training loop. Optionally, you can also add TensorFlow’s built-in Quantization aware training to reduce quantization error (but it requires changes to your training loop). Let’s demonstrate by quantizing a Keras model. Open the terminal on your development board, or SSH to your development board, and:
  1. Create a new venv and install some base packages:
  2. Download a demonstration model in .keras format, plus a test set.
  3. Create a new file quantize.py, and add:
  4. Run the example:
Great! You now have cats_i8.tflite which runs ~4x faster on the NPU (but with some accuracy loss). See Run LiteRT/TFLite models on NPU for more details on the LiteRT runtime (including C++ examples).