【发布时间】:2020-07-12 17:57:27
【问题描述】:
我在 Google Colab 中运行了这段代码,将我的 Keras hdf5 文件转换为 Tflite 文件:
import tensorflow as tf
keras_model = tf.keras.models.load_model("/content/best_model_11class.hdf5")
converter = tf.lite.TFLiteConverter.from_keras_model(keras_model)
tfmodel = converter.convert()
open ('model.tflite' , "wb") .write(tfmodel)
运行代码时出现此错误:
ValueError Traceback (most recent call last)
<ipython-input-2-0804f3b57a48> in <module>()
2 keras_model = tf.keras.models.load_model("/content/best_model_11class.hdf5")
3 converter = tf.lite.TFLiteConverter.from_keras_model(keras_model)
----> 4 tfmodel = converter.convert()
5 open ('model.tflite' , "wb") .write(tfmodel)
/usr/local/lib/python3.6/dist-packages/tensorflow/lite/python/lite.py in convert(self)
481 "None is only supported in the 1st dimension. Tensor '{0}' has "
482 "invalid shape '{1}'.".format(
--> 483 _get_tensor_name(tensor), shape_list))
484 elif shape_list and shape_list[0] is None:
485 # Set the batch size to 1 if undefined.
ValueError: None is only supported in the 1st dimension. Tensor 'input_1' has invalid shape '[None, None, None, 3]'.
谁能告诉我如何解决这个问题?
【问题讨论】:
-
(github.com/tensorflow/tensorflow/issues/22564) 检查此链接。可能会有所帮助。
标签: python-3.x keras tensorflow2.0 tensorflow-lite