如何使用 Tensorflow 模型与 tflite_diff_example_test 进行比较

How to use Tensorflow model comparison with tflite_diff_example_test

我已经训练了一个检测模型,当嵌入到 tensorflow 示例应用程序中时效果很好。
在使用 export_tflite_ssd_graph 冻结并使用 toco 转换为 tflite 之后,结果确实表现相当糟糕并且具有巨大的 "variety".

正在阅读 对类似问题的答案,但我想在 tensorflow docker 机器上尝试 tflite_diff_example_test。

由于文档现在还没有那么完善,我构建工具时参考了 this SO Post
使用: bazel build tensorflow/contrib/lite/testing/tflite_diff_example_test.cc 运行 平滑。


在找出所有需要的输入参数后,我尝试使用以下命令测试脚本:

~/.cache/bazel/_bazel_root/68a62076e91007a7908bc42a32e4cff9/external/bazel_tools/tools/test/test-setup.sh tensorflow/contrib/lite/testing/tflite_diff_example_test '--tensorflow_model=/tensorflow/shared/exported/tflite_graph.pb' '--tflite_model=/tensorflow/shared/exported/detect.tflite' '--input_layer=a,b,c,d' '--input_layer_type=float,float,float,float' '--input_layer_shape=1,3,4,3:1,3,4,3:1,3,4,3:1,3,4,3' '--output_layer=x,y'

bazel-bin/tensorflow/contrib/lite/testing/tflite_diff_example_test --tensorflow_model="/tensorflow/shared/exported/tflite_graph.pb" --tflite_model="/tensorflow/shared/exported/detect.tflite" --input_layer=a,b,c,d --input_layer_type=float,float,float,float --input_layer_shape=1,3,4,3:1,3,4,3:1,3,4,3:1,3,4,3 --output_layer=x,y

两种方式都失败了。错误:

  1. 方式: tflite_diff_example_test.cc:line 1: /bazel: Is a directory tflite_diff_example_test.cc: line 3: syntax error near unexpected token '(' tflite_diff_example_test.cc: line 3: 'Licensed under the Apache License, Version 2.0 (the "License");' /root/.cache/bazel/_bazel_root/68a62076e91007a7908bc42a32e4cff9/external/bazel_tools/tools/test/test-setup.sh: line 184: /tensorflow/: Is a directory /root/.cache/bazel/_bazel_root/68a62076e91007a7908bc42a32e4cff9/external/bazel_tools/tools/test/test-setup.sh: line 276: /tensorflow/: Is a directory

  2. 方式:

    2018-09-10 09:34:27.650473: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA Failed to create session. Op type not registered 'TFLite_Detection_PostProcess' in binary running on d36de5b65187. Make sure the Op and Kernel are registered in the binary running in this process. Note that if you are loading a saved graph which used ops from tf.contrib, accessing (e.g.)tf.contrib.resamplershould be done before importing the graph, as contrib ops are lazily registered when the module is first accessed.

非常感谢任何帮助,它使我能够使用给定测试的张量流比较两个图的输出。

你提到的第二种方式才是正确的使用方式tflite_diff。但是,包含 TFLite_Detection_PostProcess op 的对象检测模型不能通过 tflite_diff.

运行

tflite_diff 运行s 提供的 TensorFlow (.pb) 模型在 TensorFlow 运行 时间和 运行s 提供的 TensorFlow Lite (.tflite) 模型在 TensorFlow Lite 运行 时代。为了运行.pb模型在TensorFlow 运行的时候,所有的操作都必须在TensorFlow中实现。

但是,在您提供的模型中,TFLite_Detection_PostProcess 操作未在 TensorFlow 运行 时代实现 - 它仅在 TensorFlow Lite 运行 时代可用。因此,TensorFlow 无法解析 op。因此,很遗憾,您不能将 tflite_diff 工具用于此模型。