Python 我在使用tflite时收到一个resize\u tensor\u输入整形失败错误

Python 我在使用tflite时收到一个resize\u tensor\u输入整形失败错误,python,tensorflow,nlp,tensorflow-lite,bert-language-model,Python,Tensorflow,Nlp,Tensorflow Lite,Bert Language Model,因此,当我将1个输入传递给tflite模型时,模型和所有内容都正常工作。但对于批处理推断,我需要为此传递1000个值。我正在调整张量输入大小,但我得到以下错误: tensorflow/lite/kernels/reshape.cc:69 num_input_elements != num_output_elements (100000 != 100)Node number 6 (RESHAPE) failed to invoke. 我使用的代码是: interpreter.resize_ten

因此,当我将1个输入传递给tflite模型时,模型和所有内容都正常工作。但对于批处理推断,我需要为此传递1000个值。我正在调整张量输入大小,但我得到以下错误:

tensorflow/lite/kernels/reshape.cc:69 num_input_elements != num_output_elements (100000 != 100)Node number 6 (RESHAPE) failed to invoke.
我使用的代码是:

interpreter.resize_tensor_input(input_details[0]['index'], [1, 1000, 100])
interpreter.allocate_tensors()
interpreter.set_tensor(input_details[0]['index'], input_data10)
interpreter.invoke()

在最后一行,它给了我这个错误。

我能够通过更改np.expanses行来解决上述问题

最初我使用的是:

输入数据10=np。展开尺寸(输入文本[1:1001],轴=0)

我换成了 输入数据10=np。展开尺寸(输入文本[1:1001],轴=1)


因此,通过更改轴,它对我有效。

请确保您的TFLite模型可以处理任意的批量大小。如果没有,请考虑TFLITE转换与TF模型的动态尺寸在输入批量大小再次。