I get the following error from tensorflow when I try to run trained model: "Input 0 of…
- User
I get the following error from tensorflow when I try to run trained model: "Input 0 of layer "dense_3" is incompatible with the layer: expected axis -1 of input shape to have value 320320, but received input with shape (10010, 32)". Please explain what does it mean
- Assistant
This TensorFlow error message indicates a mismatch between the expected input shape for a particular layer in your neural network and the actual input shape being provided during inference.
- User
My model in tensorflow is as follows: "gas_model = tf.keras.Sequential([ tf.keras.layers.Input(shape=(10010,1)), tf.keras.layers.Conv1D(64, kernel_size=5, padding='causal', activation='sigmoid'), tf.keras.layers.Conv1D(32, kernel_size=3, padding='causal', activation='sigmoid'), #tf.keras.layers.MaxPool1D(pool_size=2), #tf.keras.layers.Conv1D(32, kernel_size=(10), input_shape = (10010,1), activation='sigmoid'), tf.keras.layers.Dropout(rate=0.1), tf.keras.layers.Flatten(), tf.keras.layers.Dense(256, activation='sigmoid'), tf.keras.layers.Dense(21*7), tf.keras.layers.Reshape((21,7)) ]) "
I train it with the features of the shape (79, 10010, 1) Then I call the trained model with the data of shape (10010, 1). I get the following error: "Input 0 of layer "dense_3" is incompatible with the layer: expected axis -1 of input shape to have value 320320, but received input with shape (10010, 32)"
Please explain what am I doing wrong.
- Assistant
The error you are encountering is due to the input shape mismatch while calling (or testing) your model post-training. Let's break it down and find out what went wrong:
-
Model Definition:
- Your model expects input of shape
(10010, 1)because of thetf.keras.layers.Input(shape=(10010, 1)). - The convolutional layers will process this input sequentially, maintaining the temporal dimension but changing the feature count as per the number of filters.
- Your model expects input of shape
-
Training Data:
- You train the model using data of shape
(79, 10010, 1), which is a batch of 79 samples, each with 10010 timesteps and 1 feature.
- You train the model using data of shape
-
Issue with Inference Input:
-
- User
My model gives the same predictions which do not depend on input data. What's going on?
- Assistant