Tensorflow-H5模型到Tflite转换错误 [英] Tensorflow - h5 model to tflite conversion error
问题描述
我已经使用预先训练的InceptionV3模型进行了学习转移,并保存了h5模型文件.之后,我就可以做出预测了. 现在,我想使用TFLiteConverter.convert()方法将h5模型转换为tflite文件,如下所示:
I've made a learning transfer using a pre-trained InceptionV3 model, and I saved the h5 model file. After that, I am able to make predictions. Now, I want to convert the h5 model to tflite file, using TFLiteConverter.convert() method, like this:
converter = lite.TFLiteConverter.from_keras_model_file('keras.model.h5')
tflite_model = converter.convert()
但我收到此错误:
File "from_saved_model.py", line 28, in <module>
tflite_model = converter.convert()
File "C:\Anaconda3\lib\site-packages\tensorflow\contrib\lite\python\lite.py", line 409, in convert
"invalid shape '{1}'.".format(_tensor_name(tensor), shape))
ValueError: None is only supported in the 1st dimension. Tensor 'input_1' has invalid shape '[None, None, None, 3]'
我正在Windows 10 64位上运行Anaconda Python 3.6.8.预先感谢您的帮助!
I am running Anaconda Python 3.6.8 on Windows 10 64 bits. Thank you in advance for your help!
推荐答案
将模型从TensorFlow转换为TensorFlow Lite时,仅允许批量大小(索引0)为None
.调用from_keras_model_file
以获得有效的输入数组形状时,您应该能够使用input_shapes
参数.对于InceptionV3模型,input_shapes
参数通常为{'Mul' : [1,299,299,3]}
.
Only the batch size (index 0) is allowed to be None
when converting the model from TensorFlow to TensorFlow Lite. You should be able to use the input_shapes
argument when calling from_keras_model_file
to get the input array shape to be valid. For an InceptionV3 model, the input_shapes
argument is often {'Mul' : [1,299,299,3]}
.
TFLiteConverter.from_keras_model_file
的文档可在此处一个>.可接受的参数如下(从文档中复制):
The documentation for TFLiteConverter.from_keras_model_file
is available here. The accepted parameters are as follows (copied from the documentation):
from_keras_model_file(
cls,
model_file,
input_arrays=None,
input_shapes=None,
output_arrays=None
)
这篇关于Tensorflow-H5模型到Tflite转换错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!