Home

Awesome

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.

Downloads GitHub Python PyPI

Environment

Motivation

The purpose is to solve the following problems by forcibly rewriting tflite's input/output OP names.

Execution

  1. Docker
    $ docker login ghcr.io
    
    Username (xxxx): {Enter}
    Password: {Personal Access Token}
    Login Succeeded
    
    $ docker run --rm -it \
    -v `pwd`:/home/user \
    ghcr.io/pinto0309/tflite-input-output-rewriter:latest
    
    $ tfliteiorewriter -i xxxx.tflite
    
  2. Local
    $ sudo apt-get update && sudo apt-get install -y flatbuffers-compiler
    # Other than debian/ubuntu: https://github.com/google/flatbuffers/releases
    $ pip install -U tfliteiorewriter
    
    $ tfliteiorewriter -i xxxx.tflite
    
usage: tfliteiorewriter
  [-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

image

image

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.

View Mode Result

tfliteiorewriter -i xxxx.tflite -v

image

Rename Mode Result

Replace with any name by specifying {From} and {To} in the --renmae (-r) option.