This tool displays tflite signatures and rewrites the input/output OP name to the name of the signature. There is no need to install TensorFlow or TFLite.
Project description
tflite-input-output-rewriter
This tool displays tflite signatures and rewrites the input/output OP name to the name of the signature. There is no need to install TensorFlow or TFLite.
Environment
- Ubuntu 20.04+
- flatbuffers-compiler
- requests
Motivation
The purpose is to solve the following problems by forcibly rewriting tflite's input/output OP names.
-
When TFLite models are generated, TensorFlow automatically prefixes the input OP name with
serving_default_
, resulting in very difficult-to-read models. Also, an unnecessary index:n
is added to the end of the name. -
Also, the output OP name is arbitrarily rewritten to the unintelligible
StatefulPartitionedCall:n
.
Execution
sudo apt-get update && sudo apt-get install -y flatbuffers-compiler
python tfliteiorewriter/main.py -i xxxx.tflite
usage: main.py [-h] -i INPUT_TFLITE_FILE_PATH [-v] [-o OUTPUT_FOLDER_PATH] [-r RENAME RENAME]
optional arguments:
-h, --help
show this help message and exit
-i INPUT_TFLITE_FILE_PATH, --input_tflite_file_path INPUT_TFLITE_FILE_PATH
Input tflite file path.
If `--rename` is not used, the input/output OP name is overwritten with the definition
information in signature_defs.
-v, --view
Runs in a mode that only displays the signature_defs recorded in the model.
This mode does not rewrite the model.
-o OUTPUT_FOLDER_PATH, --output_folder_path OUTPUT_FOLDER_PATH
Output tflite file folder path.
-r RENAME RENAME, --rename RENAME RENAME
Replace with any specified name.
--rename {from_name1} {to_name1} --rename {from_name2} {to_name2} ...
--rename serving_default_input_1:0 aaa --rename StatefulPartitionedCall:0 bbb
Execution Result
If this tool is run without additional options, it will overwrite the input/output OP names for Netron display with the input/output name definition information in signature_defs
.
-
Inputs
-
Outputs
View Mode Result
python tfliteiorewriter/main.py -i xxxx.tflite -v
Rename Mode Result
Replace with any name by specifying {From}
and {To}
in the --renmae (-r)
option.
-
Before
python tfliteiorewriter/main.py \
-i xxxx.tflite \
-r serving_default_input_1:0 aaa \
-r StatefulPartitionedCall:0 bbb
-
After
Project details
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
Hashes for tfliteiorewriter-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a664d33008862871a287ae1f1252f32d64b3aa8d2be617c6337d0850b93e2d3 |
|
MD5 | 33bc5581f5e4049bbd4c545bb2406727 |
|
BLAKE2b-256 | 287b62b59e35828d16ed8dd52a86410c008e822d70cf527161f83e761bbb02e9 |