You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As shown in the course, I have followed the same approach of loading the best performing model by using the model checkpoint callback. It worked well with the previous 4 experiments. But, when I did the same for LSTM, I am getting these errors:
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
[<ipython-input-386-3ddaf9b594a0>](https://localhost:8080/#) in <cell line: 0>()
4 # Load
5 loaded_model = tf.keras.models.load_model("./model_experiments/model_5_LSTM.keras", safe_mode=False)
----> 6 loaded_model.evaluate(test_windows, test_labels)
1 frames
[/usr/local/lib/python3.11/dist-packages/keras/src/utils/traceback_utils.py](https://localhost:8080/#) in error_handler(*args, **kwargs)
120 # To get the full stack trace, call:
121 # `keras.config.disable_traceback_filtering()`
--> 122 raise e.with_traceback(filtered_tb) from None
123 finally:
124 del filtered_tb
[/usr/local/lib/python3.11/dist-packages/keras/src/utils/python_utils.py](https://localhost:8080/#) in <lambda>(x)
9 inputs = layers.Input(shape=(WINDOW_SIZE,))
10 x = layers.Lambda(
---> 11 lambda x: tf.expand_dims(x, axis=1),
12 output_shape=(1, WINDOW_SIZE)
13 )(inputs)
NameError: Exception encountered when calling Lambda.call().
name 'tf' is not defined
Arguments received by Lambda.call():
• inputs=tf.Tensor(shape=(None, 7), dtype=float32)
• mask=None
• training=False
I know it may seem as if TensorFlow is not imported, but the thing is that I ave imported it. This is my code:
passing shape = (WINDOW_SIZE,) instead of shape = (WINDOW_SIZE) because the shape is one-dimensional and TensorFlow expects a tuple
Explicit output shape# x = layers.LSTM(128,
While normally we do not need to explicitly mention the output shape for a lamda layer, sometimes TensorFlow does need it
x = layers.LSTM(128,return_sequences = True)(x)
import tensorflow as tf
from tensorflow.keras import layers
Model definition
inputs = layers.Input(shape=(WINDOW_SIZE,))
x = layers.Lambda(
lambda x: tf.expand_dims(x, axis=1),
output_shape=(1, WINDOW_SIZE)
)(inputs)
x = layers.LSTM(128, activation="relu")(x)
x = layers.Dense(32, activation="relu")(x)
output = layers.Dense(HORIZON)(x)
model_5 = tf.keras.Model(inputs, output, name="model_5_LSTM.keras")
It might be a little bit different from the course one because I had to change some parts as they were giving errors in the latest version of TensorFlow.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
As shown in the course, I have followed the same approach of loading the best performing model by using the model checkpoint callback. It worked well with the previous 4 experiments. But, when I did the same for LSTM, I am getting these errors:
I know it may seem as if TensorFlow is not imported, but the thing is that I ave imported it. This is my code:
passing shape = (WINDOW_SIZE,) instead of shape = (WINDOW_SIZE) because the shape is one-dimensional and TensorFlow expects a tuple
Explicit output shape# x = layers.LSTM(128,
While normally we do not need to explicitly mention the output shape for a lamda layer, sometimes TensorFlow does need it
x = layers.LSTM(128,return_sequences = True)(x)
import tensorflow as tf
from tensorflow.keras import layers
Model definition
inputs = layers.Input(shape=(WINDOW_SIZE,))
x = layers.Lambda(
lambda x: tf.expand_dims(x, axis=1),
output_shape=(1, WINDOW_SIZE)
)(inputs)
x = layers.LSTM(128, activation="relu")(x)
x = layers.Dense(32, activation="relu")(x)
output = layers.Dense(HORIZON)(x)
model_5 = tf.keras.Model(inputs, output, name="model_5_LSTM.keras")
Compile the model
model_5.compile(
loss="mae",
optimizer=tf.keras.optimizers.Adam()
)
Fit the model
model_5.fit(train_windows, train_labels, epochs = 100, verbose = 1, batch_size = 128, validation_data = (test_windows, test_labels), callbacks = [create_model_checkpoint(model_name = model_5.name)])
Load
loaded_model = tf.keras.models.load_model("./model_experiments/model_5_LSTM.keras", safe_mode=False)
loaded_model.evaluate(test_windows, test_labels)
It might be a little bit different from the course one because I had to change some parts as they were giving errors in the latest version of TensorFlow.
Beta Was this translation helpful? Give feedback.
All reactions