【问题标题】:tflite.allocate_tensors() fails after changing input sizetflite.allocate_tensors() 在更改输入大小后失败
【发布时间】:2019-10-03 10:46:10
【问题描述】:

我正在尝试使用 tflite 模型对批次进行推理。我使用以下代码:

interpreter = tf.lite.Interpreter(model_path=model_path)
input_details = interpreter.get_input_details()
interpreter.resize_tensor_input(input_details[0]["index"], [batch_size, 513, 513, 3])
interpreter.allocate_tensors()

代码崩溃并给出以下错误:

RuntimeError: tensorflow/lite/kernels/reshape.cc:58 num_input_elements != num_output_elements (1579014 != 789507)Node number 0 (RESHAPE) failed to prepare.

查看输出详细信息时,它仍然具有 [1, 513, 513, output_channels] 的形状,而不是我希望的 [batch_size, 513, 513, output_channels]

有什么想法吗?

【问题讨论】:

  • 嗨。看起来问题不在 resize_tensor_input 中。您总是可以通过查看interpreter.get_input_details() 来检查resize_tensor_input 是否正常工作。或者您的帖子中有错字,您的意思是在最后一句中输入详细信息?
  • 您好,问题解决了吗?

标签: python tensorflow tensorflow-lite


【解决方案1】:

这是一个已知的错误https://github.com/tensorflow/tensorflow/issues/16216 但是暂时没有补丁

【讨论】:

    【解决方案2】:

    我遇到了类似的问题并对此进行了很多搜索。作为 tensorflow github 链接上推荐的解决方案,我使用了 tf-nightly 包,它运行良好。 安装 -

    pip install tf-nightly
    

    通过上述步骤安装 tensorflow 后,您可以按照以下步骤操作:

    from tensorflow.contrib.lite.python import interpreter
    model = Interpreter(model_path='cls_prob.tflite')
    input_details = model.get_input_details()
    req_input_size = (2, 128, 200, 1) #Your input size
    model.resize_tensor_input(input_details[0]['index'], req_input_size)
    model.allocate_tensors()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-11
      • 1970-01-01
      • 2018-10-08
      • 2021-07-25
      • 1970-01-01
      • 2016-06-01
      相关资源
      最近更新 更多