【问题标题】:How to use Tensorflow model comparison with tflite_diff_example_test如何使用 Tensorflow 模型与 tflite_diff_example_test 进行比较
【发布时间】:2018-09-10 10:22:31
【问题描述】:

我已经训练了一个检测模型,当嵌入到 tensorflow 示例应用程序中时效果很好。
在使用export_tflite_ssd_graph 冻结并使用 toco 转换为 tflite 后,结果确实表现相当糟糕并且“种类繁多”。

阅读this 回答的类似问题的准确性损失我想在 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.

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

【问题讨论】:

    标签: tensorflow bazel tensorflow-lite


    【解决方案1】:

    你提到的第二种方式是tflite_diff的正确使用方式。但是,包含TFLite_Detection_PostProcess op 的物体检测模型无法通过tflite_diff 运行。

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

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

    【讨论】:

    • 好吧,这似乎是合理的,谢谢。我没有质疑我在通往 tflite 图的路上创建的 pb 模型。我将使用export_inference_graph 生成另一个 pb。然后我应该能够比较训练好的模型。
    猜你喜欢
    • 1970-01-01
    • 2017-11-15
    • 2019-09-10
    • 1970-01-01
    • 2023-04-11
    • 1970-01-01
    • 1970-01-01
    • 2017-09-05
    • 1970-01-01
    相关资源
    最近更新 更多