• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/H04-Aug-2020-8270

3rdparty/H04-Aug-2020-1,095925

assets/H04-Aug-2020-11097

docs/H03-May-2022-

tests/H04-Aug-2020-21196

tflite/H04-Aug-2020-5,0483,349

tools/H04-Aug-2020-197145

.gitignoreH A D04-Aug-20201.2 KiB10886

LICENSEH A D04-Aug-202011.1 KiB202169

README.mdH A D04-Aug-20204.1 KiB8251

_config.ymlH A D04-Aug-202026 11

setup.cfgH A D04-Aug-2020664 1412

setup.pyH A D04-Aug-20201.5 KiB4538

README.md

1Easily Parse TFLite Models with Python
2======================================
3
4![Build and Test](https://github.com/jackwish/tflite/workflows/Build%20and%20Test/badge.svg)
5
6This [`tflite` package](https://pypi.org/project/tflite/) parses TensorFlow Lite (TFLite) models (`*.tflite`), which are built by [TFLite converter](https://www.tensorflow.org/lite/convert). For background, please refer to [Introducing TFLite Parser Python Package](https://jackwish.net/2020/introducing-tflite-parser-package.html).
7
8
9## Usage
10
11### Installation
12
13```sh
14pip install tensorflow==1.14.0
15pip install tflite==1.14.0.post1
16```
17
18It would be better if use a correct version regarding tensorflow, where the mapping is as below.
19Since `2.0.1`, the `.post[?]` suffix is not needed, such that we can keep this version map simple.
20If you notice that some version is missing, please consider [contribute it](#contributing-updates)! :)
21
22| TensorFlow package version   | tflite package version |
23|------------------------------|------------------------|
24|      1.14.0                  |      1.14.0.post1      |
25|      1.15.0                  |      1.15.0.post1      |
26|      1.15.2                  |      1.15.2            |
27|      2.0.0                   |      2.0.0.post2       |
28|      2.0.1                   |      2.0.1             |
29|      2.1.0                   |      2.1.0             |
30
31
32### Import the package
33
34The 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](https://jackwish.net/tflite/docs/).
35
36**Easy Import (Recommanded)**
37
38*Easy import* enables parsing by one single `import tflite`. This is achieved by importing classes and functions of one submodules into top module [directly](tflite/__init__.py).
39
40[MobileNet parsing example](https://github.com/jackwish/tflite/blob/master/tests/test_mobilenet.py) shows how to parse model with `import tflite` **ONLY ONCE**.
41
42**Original Import**
43
44You can use this package just like the newly FlatBuffers generated one ([example](tests/test_original_import.py)) to avoid any break of your legacy code.
45
46```python
47from tflite.Model import Model
48```
49
50
51## Contributing Updates
52
53As 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.
54
551. [Fork the repository](https://help.github.com/en/github/getting-started-with-github/fork-a-repo), and download it.
562. Install additional depdendency via `pip install -r requirements.txt`. And install [flatbuffer compiler](https://google.github.io/flatbuffers/flatbuffers_guide_using_schema_compiler.html) (you may need to [manually build it](https://google.github.io/flatbuffers/flatbuffers_guide_building.html)).
573. Generate the code for update. Tools have been prepared, there are prompt for actions.
58    1. [Download](tools/1-update-schema.sh) `schema.fbs` for a new version.
59    2. [Update](tools/2-update-importing.py) the classes and functions import of submodules.
60    3. Update the versioning in [setup.py](setup.py).
61    4. [Build](tools/3-build.sh) and [Test](tests) (simply `pytest`) around. Don't forget to re-install the newly built `tflite` package before testing it.
624. Push your change and open [Pull Request](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests).
635. The maintainer will take the responsibility to upload change to PyPI when merged.
64
65
66## Resources
67
68* [PyPI page](https://pypi.org/project/tflite/).
69* [GitHub page](https://github.com/jackwish/tflite).
70* [Module list](https://jackwish.net/tflite/docs).
71* [TensorFlow Lite converter](https://www.tensorflow.org/lite/convert).
72
73
74## License
75
76Apache License Version 2.0 as TensorFlow's.
77
78
79## Disclaimer
80
81The `schema.fbs` is obtained from TensorFlow directly. Maintainer of this package had tried to [contact](assets/disclaimer.eml) TensorFlow maintainers for licensing issues, but received no reply. Ownership or maintainship is open to transfer or close if there were any issue.
82