Reputation: 340
I am having an issue when trying to train my model in Keras 2.0.8, Python 3.6.1, and a Tensorflow Backend.
Error Message: Error when checking target: expected dense_2 to have shape (9,) but got array with shape (30,) I am providing the shape of the input as well.
train_x.shape: (623, 30, 30, 1)
train_y.shape: (623, 30)
val_x.shape: (156, 30, 30, 1)
val_y.shape: (156, 30)
#building model
model = Sequential()
model.add(Conv2D(20, (5, 5), padding="same", input_shape=(30, 30, 1), activation="relu"))
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
model.add(Conv2D(50, (5, 5), padding="same", activation="relu"))
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
model.add(Flatten())
model.add(Dense(128, activation="relu"))
model.add(Dropout(0.3))
model.add(Dense(9, activation="softmax"))
model.compile(loss="categorical_crossentropy", optimizer="adam", metrics=["accuracy"])
estop = EarlyStopping(patience=10, mode='min', min_delta=0.001, monitor='val_loss')
model.fit(train_x, train_y, validation_data=(val_x, val_y), batch_size=32, epochs=50, verbose=1, callbacks = [estop])
Upvotes: 1
Views: 76
Reputation: 1427
Change the line of code:
model.add(Dense(9, activation="softmax"))
to the below line:
model.add(Dense(30, activation="softmax"))
so that the output dimension of the last (Dense
) layer is (None, 30)
instead of dimension (None, 9)
.
Upvotes: 1