Easily Parse TFLite Models with Python

Continuous Integration

This tflite package parses TensorFlow Lite (TFLite) models (*.tflite), which are built by TFLite converter with the help of FlatBuffers. For background, please refer to Introducing TFLite Parser Python Package.

Installation

Simply install via pip. This package requires flatbuffers and numpy which should be installed automatically.

pip install tensorflow==1.14.0
pip install tflite==1.14.0.post1

It would be better if you use a correct version, where the mapping is as below.

TensorFlow package version tflite package version
1.14.0 1.14.0.post1
1.15.0 1.15.0.post1
1.15.2 1.15.2
2.0.0 2.0.0.post2
2.0.1 2.0.1
2.1.0 2.1.0

Usage

The package can be imported with easy import or original import, where the difference is how many import you write - no functionality divergence. For supported interfaces, please refer to document page.

Easy Import (Recommanded)

Easy import enables developers using parsing functionality wich one single import tflite. This is achieved by importing classes and functions of one submodules into top module directly.

MobileNet parsing example shows how to parse model with import tflite ONLY ONCE.

Original Import

You can use this package just like the newly FlatBuffers generated one (example) to avoid any break of your legacy code.

from tflite.Model import Model
# use Model

The original generated package needs to import every classes by hand (see this) which is pretty annoying.

Upgrade

Steps to upgrade this package corresponding to new TensorFlow release. Package users can safely ignore this part.

Install additional depdendency via pip install -r requirements.txt, and:

  1. Download schema.fbs for a new version.
  2. Update the classes and functions import of submodules.
  3. Update the versioning in setup.py.
  4. Build and Test around. Don’t forget to re-install the newly built tflite package before testing it.
  5. Upload the package to PyPI.

Features could be added to make the parsing easy in the future.

Resources

License

Apache License Version 2.0 as TensorFlow’s.

Disclaimer

The schema.fbs is obtained from TensorFlow directly. Maintainer of this package had tried to contact TensorFlow maintainers for licensing issues, but received no reply. Ownership or maintainship is open to transfer or close if there were any issue.