安装LSTM模型时警告
当我尝试适合我的模型时,我会遇到错误。这是代码:
model = Sequential()
model.add(LSTM(128, activation='relu', input_shape=(trainX.shape[1], trainX.shape[2]), return_sequences=True))
model.add(LSTM(64, activation='relu', return_sequences=False))
model.add(Dropout(0.2))
model.add(Dense(trainY.shape[1],'linear'))
model.compile(optimizer=Adam(learning_rate=0.0001), loss='mse')
model.summary()
运行以前的代码后,我会收到警告:
信息:TensorFlow:资产写入:c:\ users \ x \ triaade_linreg_notscaled \ cp.ckt \ Assets \ Assets 警告:absl:< keras.layers.recurrent.lstmcell对象,拨打0x0000022f630975e0>具有相同的名称“ lstmcell”与内置的keras对象。考虑重命名<类'keras.layers.recurrent.lstmcell'> gt;避免加载
tf.keras.models.models.load_model
时命名冲突。如果无法重命名,请在加载函数的custom_objects
参数中传递对象。 警告:absl:< keras.layers.recurrent.lstmcell对象,at 0x0000022f684d6a90>具有相同的名称“ lstmcell”与内置的keras对象。考虑重命名<类'keras.layers.recurrent.lstmcell'> gt;避免加载tf.keras.models.models.load_model
时命名冲突。如果无法重命名,请在custom_objects
加载函数的参数中传递对象。
import os
from tensorflow.keras.callbacks import ModelCheckpoint
checkpointpath = 'C:\\Users\\X\\training_LinReg_NotScaled/cp.ckt'
# checkpointdir = os.path.dirname(checkpointpath)
cp = ModelCheckpoint(checkpointpath, save_best_only=True)
history = model.fit(trainX, trainY, validation_data=(Xval,Yval),epochs=30, batch_size=16, callbacks=[cp],verbose=1,shuffle=False)
plt.plot(history.history['loss'], label='Training loss')
plt.plot(history.history['val_loss'], label='Validation loss')
在运行以下代码后,我会收到相同的警告:
from tensorflow.keras.models import load_model
model.save("my_model")
model = load_model("my_model")
When I try to fit my model i get an error. Here is the code:
model = Sequential()
model.add(LSTM(128, activation='relu', input_shape=(trainX.shape[1], trainX.shape[2]), return_sequences=True))
model.add(LSTM(64, activation='relu', return_sequences=False))
model.add(Dropout(0.2))
model.add(Dense(trainY.shape[1],'linear'))
model.compile(optimizer=Adam(learning_rate=0.0001), loss='mse')
model.summary()
I am getting the warnings after running the previous code:
INFO:tensorflow:Assets written to: C:\Users\X\training_LinReg_NotScaled\cp.ckt\assets
WARNING:absl:<keras.layers.recurrent.LSTMCell object at 0x0000022F630975E0> has the same name 'LSTMCell' as a built-in Keras object. Consider renaming <class 'keras.layers.recurrent.LSTMCell'> to avoid naming conflicts when loading withtf.keras.models.load_model
. If renaming is not possible, pass the object in thecustom_objects
parameter of the load function.
WARNING:absl:<keras.layers.recurrent.LSTMCell object at 0x0000022F684D6A90> has the same name 'LSTMCell' as a built-in Keras object. Consider renaming <class 'keras.layers.recurrent.LSTMCell'> to avoid naming conflicts when loading withtf.keras.models.load_model
. If renaming is not possible, pass the object in thecustom_objects
parameter of the load function.
import os
from tensorflow.keras.callbacks import ModelCheckpoint
checkpointpath = 'C:\\Users\\X\\training_LinReg_NotScaled/cp.ckt'
# checkpointdir = os.path.dirname(checkpointpath)
cp = ModelCheckpoint(checkpointpath, save_best_only=True)
history = model.fit(trainX, trainY, validation_data=(Xval,Yval),epochs=30, batch_size=16, callbacks=[cp],verbose=1,shuffle=False)
plt.plot(history.history['loss'], label='Training loss')
plt.plot(history.history['val_loss'], label='Validation loss')
And I get the same warning after running the following code:
from tensorflow.keras.models import load_model
model.save("my_model")
model = load_model("my_model")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用以下代码来抑制警告。
详细说明: -
让我们知道问题是否仍然存在。谢谢!
You can use the following code to suppress the Warnings.
In detail:-
Let us know if the issue still persists. Thanks!