I was trying to do a tutorial on time series model with tensorflow and I got an error regarding reshaping presumably coming from a reshape layer.
train_dataset = tf.keras.utils.timeseries_dataset_from_array(
train_norm,
targets=temperature_train[delay:],
sampling_rate=sampling_rate,
sequence_length=sequence_length,
shuffle=True,
batch_size=batch_size,
)
valid_dataset = tf.keras.utils.timeseries_dataset_from_array(
valid_norm,
targets=temperature_valid[delay:],
sampling_rate=sampling_rate,
sequence_length=sequence_length,
shuffle=True,
batch_size=batch_size,
)
for batch in train_dataset.take(1):
inputs, label = batch
print(inputs.shape)
print(label.shape)
break
The print results are
(64, 120, 14)
(64,)
The following assertion block raised no error for train_dataset and valid_dataset:
for batch in train_dataset:
inputs, label = batch
assert inputs.shape[1:] == (120, 14), f"{inputs.shape[1:]}"
When I build a model and start training
inputs = tf.keras.Input(shape=(inputs.shape[1:]))
x = tf.keras.layers.Flatten()(inputs)
x = tf.keras.layers.Dense(16, activation="relu")(x)
outputs = tf.keras.layers.Dense(1)(x)
model = tf.keras.Model(inputs, outputs)
model.compile("adam", loss="mse", metrics=["mae"])
callbacks = [
tf.keras.callbacks.ModelCheckpoint("jena_dense.keras", save_best_only=True)]
history = model.fit(train_dataset, validation_data = valid_dataset, epochs = 15, callbacks=callbacks )
It throws a following error
InvalidArgumentError: Graph execution error:
Detected at node functional_10_1/flatten_13_1/Reshape defined at (most recent call last)
...
...
Only one input size may be -1, not both 0 and 1
[[{{node functional_10_1/flatten_13_1/Reshape}}]] [Op:__inference_multi_step_on_iterator_40343]
The input shape for the flatten layer shouldn't be unambiguous confirming from the assertion test. I don't know where it comes from. Could someone help me?