【问题标题】:TFLite: Unable to obtain Inference using MobilenetV2 on custom DatasetTFLite:无法在自定义数据集上使用 MobilenetV2 获得推理
【发布时间】:2018-05-22 12:04:33
【问题描述】:

我已关注this 链接,并通过微调我的自定义数据集成功地为 MoiblenetV2_1.4_224 创建了冻结图。 然后,我按照tensorflow-for-poets:tflite 使用以下命令使用toco 创建了tflite 图。

IMAGE_SIZE=224
toco \
--input_file=frozen_mobilenet_v2.pb \
--output_file=optimized_graph.lite \
--input_format=TENSORFLOW_GRAPHDEF \
--output_format=TFLITE \
--input_shape=10,${IMAGE_SIZE},${IMAGE_SIZE},3 \
--input_array=input \
--output_array=MobilenetV2/Predictions/Softmax \
--inference_type=FLOAT \
--input_data_type=FLOAT

lite 图已成功创建,但在推理过程中,运行 tflite 解释器时出现以下错误。因此,我没有得到任何推论。

Input error: Failed to get input dimensions. 0-th input should have 6021120 bytes, but found 602112 bytes.

【问题讨论】:

  • 你能尝试在 Tensorboard 中可视化图表吗?或尝试转换为 pbtxt 文件并确保正确命名输入节点? import tensorflow as tf path_to_pb = '...' output_file = '...' g = tf.GraphDef() with open(path_to_pb, 'r') as f: g.ParseFromString(str(f.read())) with open(output_file, 'w') as f: f.write(str(g))
  • 我发现了问题。下面回答。原来你的标志本身有一个错字。在上下文中,请注意上述注释仅用于调试过去。

标签: android tensorflow deep-learning tensorflow-lite


【解决方案1】:

您是否尝试过这个参数--input_array=Predictions。 你可以尝试使用量化模型

【讨论】:

    【解决方案2】:

    输入错误:获取输入尺寸失败。

    命令行标志应该是--input_arrays 而不是--input_array。 (复数而不是单数)。 同上 --output_arrays 而不是 --output_array。那应该可以解决您的错误。所以命令应该是:

    IMAGE_SIZE=224
    toco \
    --input_file=frozen_mobilenet_v2.pb \
    --output_file=optimized_graph.lite \
    --input_format=TENSORFLOW_GRAPHDEF \
    --output_format=TFLITE \
    --input_shape=10,${IMAGE_SIZE},${IMAGE_SIZE},3 \
    --input_arrays=input \
    --output_arrays=MobilenetV2/Predictions/Softmax \
    --inference_type=FLOAT \
    --input_data_type=FLOAT
    

    附加调试提示

    为了将来参考,如果您的标志都正确,那么下一步就是检查您的输入和输出张量名称是否正确。您可以尝试在 Tensorboard 中可视化图表的输入和输出,或按如下方式转换为 pbtxt,然后读出:

    import tensorflow as tf
    path_to_pb = '...'
    output_file = '...'
    g = tf.GraphDef()
    with open(path_to_pb, 'rb') as f:
      g.ParseFromString(f.read())
    with open(output_file, 'w') as f:
      f.write(str(g))
    

    【讨论】:

    • 我运行了你提供的代码。它给了我以下错误。 g.ParseFromString(tmp) google.protobuf.message.DecodeError: 解析消息出错​​span>
    • 我将 open 更新为使用 'rb'。你能试一试吗?无论如何,使用 --input_arrays 是否有效?
    • 另外请注意,这只是一个额外的调试技巧。在您的情况下,事实证明标志有错字。我在答案中澄清了这一点。
    • 我有 graph.pbtxt 文件,但它包含图形的所有节点。如何识别输入和输出?
    • 你已经有了输入和输出节点:分别是'input'和'MobilenetV2/Predictions/Softmax'。所以你需要在命令行中说 --input_arrays=input \ --output_arrays=MobilenetV2/Predictions/Softmax \
    猜你喜欢
    • 2020-02-07
    • 1970-01-01
    • 1970-01-01
    • 2019-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多