user3755087
user3755087

Reputation: 1

ValueError: Error when checking target: expected dense_108 to have 2 dimensions, but got array with shape (36020, 10, 2)

I'm building a convolutional neural network with Convolution1D layer. My network model is given below. The input at dense layer seems to produce an array of shape (36020,10,2).

#network model
cnn = Sequential()
cnn.add(Convolution1D(64, 3, border_mode="same",activation="relu",input_shape=(25,1)))
cnn.add(MaxPooling1D(pool_length=(2)))
cnn.add(Flatten())
cnn.add(Dense(128, activation="relu"))
cnn.add(Dropout(0.5))
cnn.add(Dense(2, activation="softmax"))

The data I'm trying to fit the model on is:

X_train=[[[1.0000000e+00]
  [3.0122564e-08]
  [1.6120090e-05]
  ...
  [0.0000000e+00]
  [9.4886076e-08]
  [3.0170717e-08]]

 [[1.0000000e+00]
  [0.0000000e+00]
  [0.0000000e+00]
  ...
  [0.0000000e+00]
  [0.0000000e+00]
  [1.2500001e-12]]

 [[1.0000000e+00]
  [0.0000000e+00]
  [0.0000000e+00]
  ...
  [0.0000000e+00]
  [0.0000000e+00]
  [3.1249999e-11]]

 ...

 [[0.0000000e+00]
  [1.0842798e-05]
  [1.0943735e-06]
  ...
  [0.0000000e+00]
  [9.6288932e-09]
  [1.3172292e-10]]

 [[0.0000000e+00]
  [2.8011250e-01]
  [8.8251436e-01]
  ...
  [0.0000000e+00]
  [4.1974179e-04]
  [3.6202004e-04]]

 [[0.0000000e+00]
  [8.3799750e-06]
  [9.5839296e-06]
  ...
  [0.0000000e+00]
  [8.8683461e-09]
  [1.0194775e-10]]]

y_train = [[[0. 1.]
  [1. 0.]
  [1. 0.]
  ...
  [1. 0.]
  [1. 0.]
  [1. 0.]]

 [[0. 1.]
  [1. 0.]
  [1. 0.]
  ...
  [1. 0.]
  [1. 0.]
  [1. 0.]]

 [[0. 1.]
  [1. 0.]
  [1. 0.]
  ...
  [1. 0.]
  [1. 0.]
  [1. 0.]]

 ...

 [[1. 0.]
  [1. 0.]
  [1. 0.]
  ...
  [1. 0.]
  [1. 0.]
  [1. 0.]]

 [[1. 0.]
  [1. 0.]
  [1. 0.]
  ...
  [1. 0.]
  [1. 0.]
  [1. 0.]]

 [[1. 0.]
  [1. 0.]
  [1. 0.]
  ...
  [1. 0.]
  [1. 0.]
  [1. 0.]]]

I keep getting the error about the dense layer dimension. I'm really new to neural net programming.

Upvotes: 0

Views: 291

Answers (1)

today
today

Reputation: 33410

The problem is that the output shape of model, (None, 2), is inconsistent with the shape of labels array, (36020, 10, 2), you provide to it when training the model. Either you need to change the shape of labels array to (num_samples, 2) or just change the layers' parameters and architecture of the model to make it have an output shape of (None, 10, 2) (i.e. to be consistent with (36020, 10, 2)). I can't comment further as to which one is the correct way to go, since it entirely depends on what the real input and output shapes of the problem you are working on is and you have given no information in this regard.

Upvotes: 2

Related Questions