简体   繁体   中英

How do I choose the correct input shape to my Dense Layer?

I am working on a dataset with following input shapes of X and Y

print(X_train.shape, Y_train.shape)

(211968, 1024, 2) (211968, 24)

Here's my simple Model with summary and the error:

batch_size = 128
hidden_units = 256
dropout = 0.45
model = Sequential()
model.add(Dense(hidden_units,input_shape=(1024,2)))
model.add(Activation('relu'))
model.add(Dropout(dropout))
model.add(Dense(hidden_units))
model.add(Activation('relu'))
model.add(Dropout(dropout))
model.add(Dense(24))
model.add(Activation('softmax'))
model.summary()
model.compile(loss='categorical_crossentropy',optimizer='adam',metrics=['accuracy'])
model.fit(X_train, Y_train, epochs=30, batch_size=batch_size)

ValueError: Shapes (128, 24) and (128, 1024, 24) are incompatible

The input to Dense Layer must be one dimensional vector. So a Flatten() operation before the Dense Layer did the trick.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM