如何获取Tensorflow Lite模型的输入/输出特征信息?

8
我是一名移动开发人员。我想要在MLKit中使用各种Tensorflow Lite模型(.tflite)。但是有些问题,我不知道如何了解.tflite模型的输入/输出特征信息(这些参数将用于设置)。是否有任何方法可以了解这一点?对于糟糕的英语表示抱歉并感谢您的帮助。
更新(18.06.13.):
我找到了这个网站 https://lutzroeder.github.io/Netron/。它可以基于您上传的模型(例如.mlmodel.tflite等)可视化图形并查找输入/输出格式。以下是示例截图!https://lutzroeder.github.io/Netron example

当您创建tflite模型时,需要知道输入和输出类型以及形状。这就是在ML Kit中运行模型所需的所有信息。您是如何创建tflite模型的? - Pannag Sanketi
@PannagSanketi 谢谢回复。我从这里下载了MobileNet。我知道如果我想查找MobileNet的接口特征信息,可以从网页和论文中找到...但我的问题是模型中是否有输入/输出信息。(Core ML模型具有这些元信息)谢谢! - tucan9389
2个回答

8
如果您已经有一个不是由自己制作的tflite模型,并且您想要查看tflite文件并理解输入和输出,您可以使用flatc工具将模型转换为.json文件并阅读它。首先克隆flatbuffers存储库并构建flatc。
git clone https://github.com/google/flatbuffers.git

您需要在本地存储tensorflow schema.fbs文件。可以从tensorflow github检出或下载该文件。 然后,您可以运行flatc从输入的tflite模型生成json文件。

flatc -t schema.fbs -- input_model.tflite

这将创建一个 input_model.json 文件,方便阅读。

1
谢谢!这就是我想要的答案! 再次感谢您的有用提示! - tucan9389
2
我在模式定义中遇到了一个错误: 错误:schema.fbs:7:1:错误:非法字符:<有任何想法吗? - mohsaied
3
上述提到的模式文件是错误的。这个似乎可以工作: https://raw.githubusercontent.com/tensorflow/tensorflow/master/tensorflow/lite/schema/schema.fbs - mcExchange
不幸的是,json文件是一堆无意义的东西。我仍然不知道网络的预期输入和输出维度。 - mcExchange

0

补充以上答案:

请参考以下构建说明:

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.


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接