我无法将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).