ML97
ML97

Reputation: 15

How to fix error with Keras Flatten layers?

This is my code

model = keras.Sequential([
    keras.layers.Flatten(input_shape=(1,11)),    
    keras.layers.Dense(4, activation='relu'),   
    keras.layers.Dense(10, activation='softmax')  
]
)

My data is 1000 rows with 11 columns (11 inputs for the model). So to make the input layer of the NN I used flatten. This gives me the error:

WARNING:tensorflow:Model was constructed with shape (None, 1, 11) for input KerasTensor(type_spec=TensorSpec(shape=(None, 1, 11), dtype=tf.float32, name='flatten_1_input'), name='flatten_1_input', description="created by layer 'flatten_1_input'"), but it was called on an input with incompatible shape (None, 11).

Upvotes: 1

Views: 1420

Answers (1)

QWERTYL
QWERTYL

Reputation: 1373

It seems like your input shape is (num_inputs, 11) already so you don't need to flatten it. Taking out the Flatten layer should fix this.

Upvotes: 3

Related Questions