-
Notifications
You must be signed in to change notification settings - Fork 876
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
base: main
Are you sure you want to change the base?
Conversation
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
There was a problem hiding this 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>) |
There was a problem hiding this comment.
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. | ||
|
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method is not used.
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