Tensorflow tf.keras LSTM模型无法保存到SavedModel

我无法将tf.Keras LSTM模型保存到Savedmodel

1)首先重新加载保存的h5模型 2)然后尝试保存已保存的模型

# Save the entire model as a Savedmodel.
BASE_DATA_PATH = 'C:\Grewe\Classes\CS663\Mat\LSTM\data'  

#load the previously saved h5 model
# try to reload the saved h5 file
# Recreate the exact same model,including its weights and the optimizer

model_file = os.path.join(BASE_DATA_PATH,'my_model.h5')
model = tf.keras.models.load_model(model_file)
# Show the model architecture
model.summary()
#create directory to save the Savedmodel

saved_model_dir = os.path.join(BASE_DATA_PATH,'saved_model\catsdogscnn')
!mkdir -#p saved_model_dir
model.save(saved_model_dir) 

错误

ValueError: Model <tensorflow.python.keras.engine.sequential.Sequential object at 0x000001F7676BDEF0> cannot be saved because the input shapes have not been set. Usually,input shapes are automatically determined from calling .fit() or .predict(). To manually set the shapes,call model._set_inputs(inputs).
admancy 回答:Tensorflow tf.keras LSTM模型无法保存到SavedModel

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3156453.html

大家都在问