Skip to main content

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.

Downloads GitHub Python PyPI

Environment

  • Ubuntu 20.04+
  • flatbuffers-compiler (Note: Official binaries are degraded by lack of precision when processing INT8 quantized tflite files.)
  • 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.

    01

  • Also, the output OP name is arbitrarily rewritten to the unintelligible StatefulPartitionedCall:n.

    02

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.

  • Inputs

    03

  • Outputs

    04

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.

  • Before

    image

    tfliteiorewriter \
    -i xxxx.tflite \
    -r serving_default_input_1:0 aaa \
    -r StatefulPartitionedCall:0 bbb
    

    image

  • After

    image

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

tfliteiorewriter-1.1.0.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

tfliteiorewriter-1.1.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file tfliteiorewriter-1.1.0.tar.gz.

File metadata

  • Download URL: tfliteiorewriter-1.1.0.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for tfliteiorewriter-1.1.0.tar.gz
Algorithm Hash digest
SHA256 f255fb776d742eb56ca02d7ea80eb18829a3ba1aa9e792f1ab3a331881fc06a7
MD5 c88480439b76181a0a697cc747548181
BLAKE2b-256 f1da8b0ba4e4fa82f80d562b5bec1c047d68f264e92113ca2c13fc9153be0b7a

See more details on using hashes here.

File details

Details for the file tfliteiorewriter-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for tfliteiorewriter-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 118723c0feddb6d7aab93124db7f25ae89c93697677d82dd365d6ab5fcf3e7ec
MD5 f8abbcd41d7573aba77ca0bb64196de7
BLAKE2b-256 35b239425a8b3089561017ab7683aea9cee16246fd9b15ee67a388eeffd4e4bd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page