0

I hit with the error message on my model; 'ValueError: Input 0 of layer sequential_5 is incompatible with the layer: expected axis -1 of input shape to have value 20 but received input with shape (None, 20, 637)'

Im not sure how to fix this. Code as below;

print(str(audio_train.shape)+''+str(y_train.shape)+''+str(audio_valid.shape))

(700, 20, 637) (700, 2) (236, 20, 637)

model=Sequential()
###first layer
model.add(Dense(100,input_shape=(20,)))
model.add(Activation('relu'))
model.add(Dropout(0.3))
###second layer
model.add(Dense(200))
model.add(Activation('relu'))
model.add(Dropout(0.3))
###third layer
model.add(Dense(100))
model.add(Activation('relu'))
model.add(Dropout(0.3))
###final layer
model.add(Dense(2))
model.add(Activation('softmax'))
model.summary()

adam = tf.keras.optimizers.Adam(learning_rate=0.0001)
model.compile(optimizer = adam, loss = 'categorical_crossentropy', metrics = ['accuracy'])
#fitting the model
Au_model = model.fit(audio_train, y_train, batch_size = 32, epochs = 10, validation_data = (audio_valid, y_valid), verbose=1)

Error message as below;

ValueError: in user code:

C:\Users\seren\anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py:855 train_function  *
    return step_function(self, iterator)
C:\Users\seren\anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py:845 step_function  **
    outputs = model.distribute_strategy.run(run_step, args=(data,))
C:\Users\seren\anaconda3\lib\site-packages\tensorflow\python\distribute\distribute_lib.py:1285 run
    return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
C:\Users\seren\anaconda3\lib\site-packages\tensorflow\python\distribute\distribute_lib.py:2833 call_for_each_replica
    return self._call_for_each_replica(fn, args, kwargs)
C:\Users\seren\anaconda3\lib\site-packages\tensorflow\python\distribute\distribute_lib.py:3608 _call_for_each_replica
    return fn(*args, **kwargs)
C:\Users\seren\anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py:838 run_step  **
    outputs = model.train_step(data)
C:\Users\seren\anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py:795 train_step
    y_pred = self(x, training=True)
C:\Users\seren\anaconda3\lib\site-packages\tensorflow\python\keras\engine\base_layer.py:1013 __call__
    input_spec.assert_input_compatibility(self.input_spec, inputs, self.name)
C:\Users\seren\anaconda3\lib\site-packages\tensorflow\python\keras\engine\input_spec.py:251 assert_input_compatibility
    raise ValueError(

ValueError: Input 0 of layer sequential_5 is incompatible with the layer: expected axis -1 of input shape to have value 20 but received input with shape (None, 20, 637)

Appreciate your advice/suggestion.

2
  • What's the shape of y_valid? Commented Jul 5, 2022 at 6:59
  • y_valid => (236,2) Commented Jul 5, 2022 at 7:46

1 Answer 1

1

Change

model.add(Dense(100,input_shape=(20,)))

To

model.add(Dense(100,input_shape=(20, 637)))

You can also use input_shape=(audio_train.shape[1], audio_train.shape[2]) instead if you wanted to be a bit more programmatic.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.