我使用预训练的 InceptionV3 模型进行了学习迁移,并保存了 h5 模型文件。之后,我就能做出预测。
现在,我想使用 TFLiteConverter.convert() 方法将 h5 模型转换为 tflite 文件,如下所示:
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。预先感谢您的帮助!
仅允许批量大小(索引 0)None
将模型从 TensorFlow 转换为 TensorFlow Lite 时。您应该能够使用input_shapes
调用时的参数from_keras_model_file
使输入数组形状有效。对于 InceptionV3 模型,input_shapes
争论常常是{'Mul' : [1,299,299,3]}
.
的文档TFLiteConverter.from_keras_model_file
可用here https://www.tensorflow.org/api_docs/python/tf/contrib/lite/TFLiteConverter#from_keras_model_file。接受的参数如下(从文档复制):
from_keras_model_file(
cls,
model_file,
input_arrays=None,
input_shapes=None,
output_arrays=None
)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)