I am studying Deep Learning with Python Book by François Chollet book chapter 10.2.5 I use tensorflow 2.4.1
.
Here is the code for weather forcast by LSTM :
inputs = keras.Input(shape=(sequence_length, raw_data.shape[-1]))
x = layers.LSTM(16)(inputs)
outputs = layers.Dense(1)(x)
model = keras.Model(inputs, outputs)
callbacks = [
keras.callbacks.ModelCheckpoint("jena_lstm.keras",
save_best_only=True)
]
model.compile(optimizer="rmsprop", loss="mse", metrics=["mae"])
history = model.fit(train_dataset,
epochs=10,
validation_data=val_dataset,
callbacks=callbacks)
model = keras.models.load_model("jena_lstm.keras")
print(f"Test MAE: {model.evaluate(test_dataset)[1]:.2f}")
When I try to pass the input to LSTM layes I face the following Error:
–> 852 raise NotImplementedError( 853 “Cannot convert a symbolic Tensor ({}) to a numpy array.” 854 ” This error may indicate that you’re trying to pass a Tensor to”
NotImplementedError: Cannot convert a symbolic Tensor (lstm_6/strided_slice:0) to a numpy array. This error may indicate that you’re trying to pass a Tensor to a NumPy call, which is not supported
I have no problem with Dense layer or conv2D layer I can’t pass the input for LSTM layer. any Idea why?
the inputs is jena_climate_2009_2016.csv.zip dataset from keras. build like this:
train_dataset = tf.keras.preprocessing.timeseries_dataset_from_array(
raw_data[:-delay],
targets=temperature[delay:],
sampling_rate=sampling_rate,
sequence_length=sequence_length,
shuffle=True,
batch_size=batch_size,
start_index=0,
end_index=num_train_samples)
I solve the problem by downgrading numpy from 1.21 to 1.19