【问题标题】:Retrained Tflite/Pb models extracted from the same checkpoint give different results从同一检查点提取的再训练 Tflite/Pb 模型给出不同的结果
【发布时间】:2019-08-07 23:50:06
【问题描述】:

在我使用 object_detection\model_main.py 脚本用我自己的图像数据集重新训练预训练的 ssd mobilenet v1 模型后,我导出了两个 .pb 冻结图(使用 export_inference_graph.py 脚本)

python models\research\object_detection\export_inference_graph.py 
--input_type image_tensor 
--input_shape=1,300,300,3 
--pipeline_config_path ssd_mobilenet_v1_test.config 
--trained_checkpoint_prefix training/model.ckpt 
--output_directory export\freeze\

和 .tflite 图形(带有 export_tflite_ssd_graph.py 脚本和 tflite_convert)。

python models\research\object_detection\export_tflite_ssd_graph.py 
--input_type image_tensor 
--pipeline_config_path ssd_mobilenet_v1_test.config 
--trained_checkpoint_prefix training/model.ckpt 
--output_directory export\tflite\ 
--max_detections 16 
--add_postprocessing_op=true

tflite_convert 
--output_file=export\tflite\model.tflite 
--graph_def_file=export\tflite\tflite_graph.pb 
--input_shapes=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 
--inference_type=QUANTIZED_UINT8 
--mean_values=128 
--std_dev_values=128 
--default_ranges_min=0 
--default_ranges_max=6 
--allow_custom_ops

Pb 图表似乎工作得很好,但是 tflite one 错误地检测到了 android 上的所有内容,所以无论我传递给它的任何图像,我都会在 16 个可能的检测中得到 16 个,甚至是填充黑色的图像(我在 android 设备上测试它. 它适用于预训练模型)。

更改转换选项(例如禁用/启用量化、图像标准/均值)并没有改变任何东西。我还将我的 tflite 图与示例 mobilenet 图进行了比较,它们看起来非常相似。有什么想法会导致这个问题吗?

(windows 10/cuda 9.0/cudnn 7.0/tf-nightly-gpu/models-master)

【问题讨论】:

  • 您是否尝试过在 Python 中运行推理以确保 Android 集成没有问题?如果是这样,您能否在 TensorFlow 的 GitHub 页面上提交 issue 并包含重现问题所需的所有内容,包括模型(或模型的最小版本)。

标签: java python tensorflow tensorflow-lite


【解决方案1】:

tflite 模型的输出张量似乎返回了一些极值(例如:5e35 或 -3e34)。由于其中一些得分值大于 1,因此它被视为检测。

我的解决方案,用 0 替换所有大于限制的值(我做了 1e5)。(Python 更快。)

tensor[tensor > 1e5] = 0

奇怪的是,示例 detector.tflite 或导出的冻结推理图不会发生这种情况。导出 tflite 模型必须有正确的方法。

【讨论】:

    猜你喜欢
    • 2021-08-24
    • 2019-03-29
    • 2021-01-10
    • 2015-06-25
    • 1970-01-01
    • 1970-01-01
    • 2018-06-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多