我最近保存了一些我在另一台机器上训练过的模型,并且没有像我在另一个模型中所看到的那样保存它,并且使用了h5扩展。我还不知道如何装重物。我可以加载模型,但没有重量意味着什么都没有。请帮助:-)
from keras.models import load_model
from keras.models import model_from_json
model_LSTM_rendimiento = keras.models
model_LSTM_super = keras.models
model_LSTM_primero = keras.models
model_LSTM_rendimiento.load_model('../model_LSTM_rendimiento')
model_LSTM_super.load_model('../model_LSTM_super')
model_LSTM_primero.load_model('../model_LSTM_primero')
model_LSTM_primero.load_weights('../model_LSTM_primero_weights')
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/tmp/ipykernel_186379/3422008780.py in <module>
12 # model_LSTM_super.load_weights('../model_LSTM_super_weights')
13 model_LSTM_primero.load_model('../model_LSTM_primero')
---> 14 model_LSTM_primero.load_weights('../model_LSTM_primero_weights')
AttributeError: module 'keras.models' has no attribute 'load_weights'发布于 2022-09-22 17:36:31
由于您还没有以h5格式保存模型,所以我假设您使用了如下所示的SavedModel格式:
model.save('path/to/location')如果这就是您所做的,那么像这样加载模型就足够了:
model = keras.models.load_model('path/to/location')您不必分别加载权重;来自SavedModel 文档
SavedModel是更全面的保存格式,它保存了调用函数的模型体系结构、权重和跟踪的Tensorflow子图。这使得Keras能够同时恢复内置层和自定义对象。
你的代码:
from tensorflow import keras
model_LSTM_rendimiento = keras.models.load_model('../model_LSTM_rendimiento')
model_LSTM_super = keras.models.load_model('../model_LSTM_super')
model_LSTM_primero = keras.models.load_model('../model_LSTM_primero')https://stackoverflow.com/questions/73818490
复制相似问题