user3729332
user3729332

Reputation: 81

input output dimension in keras dense layer

I am trying to implement a dense layer in keras. The input is EEG recording using 2 channels, each of them consist of a vector of 8 points and the total number of training points is 17. The y is also 17 points.

I used

x=x.reshape(17,2,8,1)
y=y.reshape(17,1,1,1)

model.add(Dense(1, input_shape=(2,8,1), activation='relu'))
print(model.summary())
model.compile(loss='sparse_categorical_crossentropy', optimizer='adam')
print(model.compile)

model.fit(x, y, batch_size = 17,epochs=500, verbose=1)

but i get the following error

Error when checking target: expected dense_57 to have shape (2, 8, 1) but got array with shape (17, 1, 1)

Upvotes: 0

Views: 104

Answers (1)

learner
learner

Reputation: 3472

Since the Dense layer has output dimension 1, it would expect y to be of the shape (2, 8, 1). An easy fix would be to do the following

x = x.reshape(17, 16)
y = y.reshape(17, 1)

model.add(Dense(1, input_shape=(16,), activation='relu'))

Upvotes: 3

Related Questions