'Warning when fitting the LSTM 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 with tf.keras.models.load_model. If renaming is not possible, pass the object in the custom_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 with tf.keras.models.load_model. If renaming is not possible, pass the object in the custom_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")


Solution 1:[1]

You can use the following code to suppress the Warnings.

import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
import tensorflow as tf

In detail:-

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

Let us know if the issue still persists. Thanks!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tfer3