如何使用相同的测试数据测试 .tflite 模型以证明它的行为与原始模型一样?
How can I test a .tflite model to prove that it behaves as the original model using the same Test Data?
我已经根据经过训练的模型生成了一个 .tflite 模型,我想测试一下 tfilte 模型是否给出与原始模型相同的结果。
给出相同的测试数据并获得相同的结果。
TensorFlow 代码库中有一个tflite_diff_example_test。它生成随机数据并将相同的数据输入 TensorFlow 和 TensorFlow lite,然后比较差异是否在一个小阈值内。
您可以从 Github 检出 TensorFlow 代码,并 运行 使用 bazel:
bazel run //tensorflow/contrib/lite/testing:tflite_diff_example_test
然后您会看到需要传递哪些参数。
除了@miaout17给出的答案,调试/理解你的tflite模型(这才是问题的精神),你可以
- 使用
--dump_graphviz
可视化图表,如此处所述 https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/lite/toco/g3doc/cmdline_examples.md#using---dump_graphviz
- 使用
flatc
生成pythonapi然后通过api解析模型
https://google.github.io/flatbuffers/flatbuffers_guide_use_python.html
- 使用
flatc
从tflite
文件生成json
并打印出来
- 使用 tflite 可视化工具:
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/lite/tools/visualize.py (currently has a bug)
您可以使用 TensorFlow Lite Python 解释器 来测试您的 tflite 模型。
它允许您在 python shell 中输入数据并直接读取输出,就像您只是在使用普通的 tensorflow 模型一样。
我已经回答了这个问题here。
您可以阅读此 TensorFlow lite official guide 了解详细信息。
您还可以使用 Netron 可视化您的模型。它允许您直接加载 .tflite 文件并检查您的模型架构和模型权重。
我已经根据经过训练的模型生成了一个 .tflite 模型,我想测试一下 tfilte 模型是否给出与原始模型相同的结果。
给出相同的测试数据并获得相同的结果。
TensorFlow 代码库中有一个tflite_diff_example_test。它生成随机数据并将相同的数据输入 TensorFlow 和 TensorFlow lite,然后比较差异是否在一个小阈值内。
您可以从 Github 检出 TensorFlow 代码,并 运行 使用 bazel:
bazel run //tensorflow/contrib/lite/testing:tflite_diff_example_test
然后您会看到需要传递哪些参数。
除了@miaout17给出的答案,调试/理解你的tflite模型(这才是问题的精神),你可以
- 使用
--dump_graphviz
可视化图表,如此处所述 https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/lite/toco/g3doc/cmdline_examples.md#using---dump_graphviz - 使用
flatc
生成pythonapi然后通过api解析模型 https://google.github.io/flatbuffers/flatbuffers_guide_use_python.html - 使用
flatc
从tflite
文件生成json
并打印出来 - 使用 tflite 可视化工具: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/lite/tools/visualize.py (currently has a bug)
您可以使用 TensorFlow Lite Python 解释器 来测试您的 tflite 模型。
它允许您在 python shell 中输入数据并直接读取输出,就像您只是在使用普通的 tensorflow 模型一样。
我已经回答了这个问题here。
您可以阅读此 TensorFlow lite official guide 了解详细信息。
您还可以使用 Netron 可视化您的模型。它允许您直接加载 .tflite 文件并检查您的模型架构和模型权重。