8

I'm mobile developer. And I want to use various Tensorflow Lite models(.tflite) with MLKit.

But there are some issues, I have no idea of how to know .tflite model's input/output feature info(these will be parameters for setup).

Is there any way to know that?

Sorry for bad English and thanks.


Update(18.06.13.):

I found this site https://lutzroeder.github.io/Netron/. This visualize graph based on your uploaded model(like .mlmode or .tflite etc.) and find input/output form.

Here is example screenshot! https://lutzroeder.github.io/Netron example

tucan9389
  • 168
  • 2
  • 10
  • When you create the `tflite` model, you need to know the input and output types and shapes. And that is all the info you need to run the model in ML Kit. How are you creating the tflite model? – Pannag Sanketi Jun 01 '18 at 16:09
  • @PannagSanketi Thanks for replay. I downloaded from [here](https://www.tensorflow.org/mobile/tflite/demo_android), MobileNet. I know about that if I try to find MobileNet's interface features info, I can find from webpage and papers.. But my question is whether I have input / output info in the model. (The Core ML model has those meta info) Thanks! – tucan9389 Jun 01 '18 at 23:59

2 Answers2

8

If you already have a tflite model that you did not produce yourself, and you want to look inside the tflite file and understand your inputs and outputs, you can use flatc tool and convert the model to .json file and read that.

First clone the flatbuffers repo and build flatc.

git clone https://github.com/google/flatbuffers.git

Then you have to have the tensorflow schema.fbs stored locally. Either checkout the tensorflow github or download that one file. Then you can run flatc to generate the json file from then input tflite model.

flatc -t schema.fbs -- input_model.tflite

This will create a input_model.json file that can be easily read.

Pannag Sanketi
  • 1,372
  • 1
  • 10
  • 10
  • 1
    Thanks! This is the answer what I want! Thanks again helpful hint! – tucan9389 Jun 02 '18 at 00:05
  • 2
    I'm getting an error in the schema definition: error: schema.fbs:7: 1: error: illegal character: < any ideas? – mohsaied May 30 '19 at 09:59
  • 3
    The schema file mentioned above is wrong. This one seems to be working: https://raw.githubusercontent.com/tensorflow/tensorflow/master/tensorflow/lite/schema/schema.fbs – mcExchange May 31 '19 at 13:08
  • Unfortunately the json file is a bunch of gibberish. I still don't know the expected input and output dimensions of the network – mcExchange May 31 '19 at 13:17
0

Adding to the above answer:

See these instructions for building:

https://google.github.io/flatbuffers/md__building.html

If you already have a tflite model that you did not produce yourself, and you want to look inside the tflite file and understand your inputs and outputs, you can use flatc tool and convert the model to .json file and read that.

First clone the flatbuffers repo and build flatc.

git clone https://github.com/google/flatbuffers.git

Then you have to have the tensorflow schema.fbs stored locally. Either checkout the tensorflow github or download that one file. Then you can run flatc to generate the json file from then input tflite model.

flatc -t schema.fbs -- input_model.tflite

This will create a input_model.json file that can be easily read.

Saurabh Kachhia
  • 300
  • 3
  • 12
CraigDavid
  • 1,046
  • 1
  • 12
  • 26