当我尝试适合我的模型时,我得到一个错误。下面是代码:
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()
在运行前面的代码后,我得到了警告:
INFO:tensorflow:Assets写入:C:UsersXtraining_LinReg_NotScaledcp.ckt Assets警告:absl: & lt; keras.layers.recurrent。lstcell对象在0x0000022F630975E0>具有与内置Keras对象相同的名称'LSTMCell'。考虑重命名类"keras.layers.recurrent.LSTMCell">在加载
tf.keras.models.load_model
时避免命名冲突。如果不能重命名,则在load函数的custom_objects
参数中传递对象。警告:absl: & lt; keras.layers.recurrent。lstcell对象在0x0000022F684D6A90>具有与内置Keras对象相同的名称'LSTMCell'。考虑重命名类"keras.layers.recurrent.LSTMCell">在加载tf.keras.models.load_model
时避免命名冲突。如果不能重命名,则在load函数的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")
您可以使用以下代码来禁用警告。
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
import tensorflow as tf
详细: -
0 = all messages are logged (default behavior)
1 = INFO messages are not printed
2 = INFO and WARNING messages are not printed
3 = INFO, WARNING, and ERROR messages are not printed
如果问题仍然存在,请告诉我们。谢谢!