【问题标题】:Integrate tflite model with tensorflow object-detection example code将 tflite 模型与 tensorflow 对象检测示例代码集成
【发布时间】:2020-11-12 07:23:09
【问题描述】:

我有一个 tflite 模型,我通过转换我的 TF 模型(MobileNet Single Shot Detector (v2))获得。

我已经使用下面的代码成功地将我的模型转换为 tflite 格式。

!tflite_convert \
  --input_shape=1,300,300,3 \
  --input_arrays=normalized_input_image_tensor \
  --output_arrays=TFLite_Detection_PostProcess,TFLite_Detection_PostProcess:1,TFLite_Detection_PostProcess:2,TFLite_Detection_PostProcess:3 \
  --allow_custom_ops \
  --graph_def_file=/content/models/research/fine_tuned_model/tflite/tflite_graph.pb \
  --output_file="/content/models/research/fine_tuned_model/final_model.tflite"

并已尝试将其集成到 tensorflow 团队提供的对象检测代码中。但输出不可见。

我的整合步骤如下: 1.从 build.gradle(app) 中注释以下行

apply from:'download_model.gradle'
  1. 我在 assets 文件夹中添加了我的 tflite 模型,并用我自己的标签修改了 label.txt。
  2. 在检测器活动中,
private static final boolean TF_OD_API_IS_QUANTIZED = true;

我已将上述布尔值设置为 false

并将概率降低到 0.2

 private static final float MINIMUM_CONFIDENCE_TF_OD_API = 0.5f;

但是没有用。

对象检测代码的 github 链接:- https://github.com/tensorflow/examples/blob/master/lite/examples/object_detection/android

另外,请告知如何使用测试图像测试 tflite 模型的工作。

这些是调试模型后的值

[[[ 0.15021165  0.45557776  0.99523586  1.009417  ]
  [ 0.4825344   0.18693507  0.9941584   0.83610606]
  [ 0.36018616  0.612343    1.0781565   1.1020089 ]
  [ 0.47380492  0.03632754  0.99250865  0.5964786 ]
  [ 0.15898478  0.12117874  0.94728076  0.8854655 ]
  [ 0.44774154  0.41910237  0.9966481   0.9704595 ]
  [ 0.06241751 -0.02005028  0.93670964  0.3915068 ]
  [ 0.1917564   0.00806974  1.0165613   0.5287838 ]
  [ 0.20279509  0.738887    0.95690674  1.0022873 ]
  [ 0.7434618   0.07342905  0.9969055   0.6412263 ]]]

【问题讨论】:

  • 错误是什么?
  • 转换后的模型是否按预期工作?我建议您开始使用python 运行您的 tflite 模型进行故障排除,并检查结果是否正确。

标签: android-studio tensorflow tensorflow-lite object-detection-api


【解决方案1】:

首先训练你的模型。最好使用经过训练的模型。训练模型后,获取 tflite 图并使用 Bazel 将它们转换为 tflite 模型(最好使用 Ubuntu)。然后获取 Tensorflow/examples 并在您的 Android Studio 上打开对象检测 android 文件夹。 从 tflite 解释器类中删除元数据代码,因为它需要它并且官方没有官方声明的方式来实现它。然后你就可以让它工作了。

【讨论】:

    猜你喜欢
    • 2021-01-15
    • 2020-02-15
    • 2021-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-28
    • 2020-06-03
    • 1970-01-01
    相关资源
    最近更新 更多