Skip to content

feat: add tool for visualizing compressed (and uncompressed) models #3099

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rkuester
Copy link
Contributor

Add a development tool that prints compressed and uncompressed
.tflite models to stdout in a human-readable, searchable,
structured, text format. Helpful annotations (indexes of lists,
names of operators, etc.) derived from the model are added as
virtual fields with names beginning with an _underscore.

Add a unit test which simply ensures the viewer does not crash
when run on several models found in the source tree.

BUG=see description

Add a development tool that prints compressed and uncompressed
.tflite models to stdout in a human-readable, searchable,
structured, text format. Helpful annotations (indexes of lists,
names of operators, etc.) derived from the model are added as
virtual fields with names beginning with an _underscore.

Add a unit test which simply ensures the viewer does not crash
when run on several models found in the source tree.

BUG=see description
@rkuester rkuester requested a review from a team as a code owner April 24, 2025 03:47
@TFLM-bot TFLM-bot removed the ci:run label Apr 24, 2025
Copy link
Member

@ddavis-2015 ddavis-2015 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a way to see the compressed bitstrings as a list of LUT indices. Maybe with an optional flag?

from tensorflow.lite.python import schema_py_generated as tflite_schema

USAGE = textwrap.dedent(f"""\
Usage: {os.path.basename(sys.argv[0])} $(realpath <MODEL>)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that $(realpath <MODEL>) somehow expanded? I'm thinking the output should just be view <model path>. On the other hand, if tensorflow.lite.micro.compression isn't in the PyPi, then this script can only be run using Bazel, in which case the person running the Bazel command would probably know what $(realpath) is?

# Convert the model into a Python dictionary, expressing the hierarchial nature
# of the model, and pretty print the dictionary. Please extend as needed for
# your use case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a bazel run command line example here.

} for t in sorted(lut_tensors, key=lambda x: x.tensor)]


def is_compressed_buffer(buffer_index, unpacked_metadata):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method not used. I believe this was part of the code I added to show compressed bitstrings as lists of indices.

return False, None, None


def unpack_indices(buffer, lut_data):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method not used. I believe this was part of the code I added to show compressed bitstrings as lists of indices.

return indices


def unpack_compression_metadata(buffer):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method is not used.

return buffers


def get_compression_metadata_buffer(model):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method is not used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants