Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Parse toco generated file (.tflite) in python? #16561
Describe the problem
I am using toco to optimize a frozen model (.pb). How do I read the .tflite file in python - something similar to tf.gfile.GFile('frozen.pb', 'rb')?
I am trying to read/parse the model, convert it to our internal format, and then run inference on it.
As a workaround (to not being able to parse tflite), I set the output_format while running toco tool to TENSORFLOW_GRAPHDEF (i.e. both input and output formats are TENSORFLOW_GRAPHDEF). And then parse the generated protobuf.
However, I see that protobuf is "less" optimized compared to tflite
Following is the log when output_format is TENSORFLOW_GRAPHDEF:
Following is the log when output_format is set to TFLITE:
The number of operators after graph transformation is different (141 v/s 84) while the estimated count of arithmetic ops is same (3.01265 billion).
well you can use flatc to generate a python api that can read the tflite format.
@santoshchilkunda, it is an inherent characteristic of the TensorFlow Lite flatbuffer format that it allows to represent the same neural network in fewer nodes than are needed in the TensorFlow GraphDef format, as you found from this logging. To find out more about what the difference is in your graph, use --dump_graphviz as explained there,
Another approach is to generate json from the flatbuffer using flatc. This is used by the tflite visualizer:
@aselle could you please make it a little bit clear for me
I am using pyhon generated code to read and get node attributes from the model graph.
I generated it this way (output is
Than I read the model:
Getting model parameters:
Than I realized that graph nodes could be interpreted as
I tried to iterate over them since there are Inputs and Outputs methods. But failed. I don't understand w
This is my scratch:
Please help me to get access the node attributes.