Home > Mobile >  ValueError: Shapes (None, 9) and (None, 22000, 9) are incompatible
ValueError: Shapes (None, 9) and (None, 22000, 9) are incompatible

Time:08-24

The following is my code: The shape of my X_train is TensorShape([600, 22000, 5]) The shape of my Y_train is (600, 9) Is there an error with the type of data that I am using for this time-series problem?

model = Sequential()
model.add(LSTM(256,return_sequences=True,input_shape=(22000, 5)))
model.add(Dense(9, activation='softmax'))
model.compile(optimizer='adam',loss='categorical_crossentropy', metrics=['accuracy'])
print(model.summary())

#print(model.summary())
model.fit(allfileswow[:600], features_a1[:600], epochs=100,verbose=0)

CodePudding user response:

Hi just like @Djinn mentioned add a flatten layer to make everything 1-D

model = Sequential()
model.add(LSTM(256,return_sequences=True,input_shape=(22000, 5)))
model.add(Flatten())
model.add(Dense(9, activation='softmax'))
model.compile(optimizer='adam',loss='categorical_crossentropy', metrics=['accuracy'])
print(model.summary())

CodePudding user response:

Try removing 'return_sequences=True' as you don't need full sequence as the output for the next layer. Refer lstm

  • Related