Parsing TensorFlow Lite Models (*.tflite) Easily
Project description
Easily Parse TFLite Models with Python
This tflite
package parses TensorFlow Lite (TFLite) models (*.tflite
), which are built by TFLite converter. For background, please refer to Introducing TFLite Parser Python Package.
Usage
Install the package and use it like what you build from the TensorFlow codebase. It's recommended to install the version that same as the TensorFlow that generates the TFLite model.
pip install tensorflow==2.3.0
pip install tflite==2.3.0
The raw API of tflite
can be found in this documentation.
The MobileNet test can serve as a usage example of parsing models.
Enhancements
The generated python package is not friendly to use sometimes. We have introduced several enhancements:
- Easy import: A single
import tflite
(example) to replace importing every classes and funtions intflite
(example). - Builtin opcode helper: The opcode is encoded as digits which is hard to parse for human. Two APIs added to make it easy to use.
tflite.opcode2name()
: get the type name of given opcode.tflite.BUILTIN_OPCODE2NAME
: a dict that maps the opcode to name of all the builtin operators.
Compatibility Handling
TensorFlow sometimes leaves compability hanlding of the TFLite model to the users.
As these are API breaking change that can be easily fixed, we do this in the tflite
package.
tflite.OperatorCode.BuiltinCode()
: maintains API compability in2.4.0
, see this issue.
Contributing Updates
As the operator definition may change across different TensorFlow versions, this package needs to be updated accordingly. If you notice that the package is out of date, please feel free to contribute new versions. This is pretty simple, instructions as below.
- Fork the repository, and download it.
- Install additional depdendency via
pip install -r requirements.txt
. And install flatbuffer compiler (you may need to manually build it). - Generate the code for update. Tools have been prepared, there are prompt for actions.
- Download
schema.fbs
for a new version. - Update the builtin operator mapping.
- Update the classes and functions import of submodules.
- Update the API document.
- Update the versioning in
__init__.py
. - Build and test (simply
pytest
) around. Don't forget to re-install the newly builttflite
package before testing it.
- Download
- Push your change and open Pull Request.
- The maintainer will take the responsibility to upload change to PyPI when merged.
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file tflite-2.10.0.tar.gz
.
File metadata
- Download URL: tflite-2.10.0.tar.gz
- Upload date:
- Size: 38.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6818a5d7776958b803944ba0a1f4c4395559606d9e795d67ac467a8a3904757d |
|
MD5 | b0b3f5e7edbbd2b39bd3bf524e180ec4 |
|
BLAKE2b-256 | 0da88e84e361b77733157e04bac54b1479f877f3185cdc0dbbc412823fbfc7c8 |
File details
Details for the file tflite-2.10.0-py2.py3-none-any.whl
.
File metadata
- Download URL: tflite-2.10.0-py2.py3-none-any.whl
- Upload date:
- Size: 123.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89cb9f57df0f5345f8fad1381e0fae6180ded687113eb552cfbb60a05edc002c |
|
MD5 | c5fd04acc67854ccf9d4af2088d7505d |
|
BLAKE2b-256 | 928d20f655ab797c65613edcfc7354a80f288444f561c419bc638fe501c5f292 |