我正在尝试使用 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]
我希望如此。
有什么想法吗?
最佳答案
这是一个已知错误 https://github.com/tensorflow/tensorflow/issues/16216 但目前没有补丁
关于python - 更改输入大小后 tflite.allocate_tensors() 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58217497/