schil
schil

Reputation: 322

How to parse toco generated file (.tflite) in python?

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')?

Upvotes: 3

Views: 1765

Answers (2)

sven
sven

Reputation: 126

.tflite file is flatbuffer format, as far as I know, there are two ways to parse info from .tflite file:
1.Parse by flatc and json. Tensorflow has implemented the parse function in visualize.py, which is in tensorflow/contrib/lite/tools, you can refer to it for parsing.
2.Parse by pure python. Flatbuffer format file has a schema, which can generate code for different programming language(link:https://google.github.io/flatbuffers/flatbuffers_guide_tutorial.html), you will get a series of python file, and you can use following code to parse the .tflite file:

from Model import Model
buf = open('you-tflite-file', 'rb').read()
buf = bytearray(buf)
model = Model.getRootAsModel(buf, 0)

Now you can get information from the model object.

Upvotes: 3

Laurence Moroney
Laurence Moroney

Reputation: 1263

The point isn't to read it in Python -- it's for Android and iOS where there are C++ libraries to read it (with a Java Wrapper for Android)

Upvotes: 0

Related Questions