I'm working on a sign language interpretation using deep learning & for that, i'm building a CNN and i am getting an error like,
ValueError: Error when checking target: expected dense_20 to have shape (24,) but got array with shape (1,)
structure of my neural net:
Layer (type) Output Shape Param #
conv2d_62 (Conv2D) (None, 64, 64, 64) 1088
_________________________________________________________________
conv2d_63 (Conv2D) (None, 32, 32, 64) 65600
_________________________________________________________________
dropout_31 (Dropout) (None, 32, 32, 64) 0
_________________________________________________________________
conv2d_64 (Conv2D) (None, 32, 32, 128) 131200
_________________________________________________________________
conv2d_65 (Conv2D) (None, 16, 16, 128) 262272
_________________________________________________________________
dropout_32 (Dropout) (None, 16, 16, 128) 0
_________________________________________________________________
conv2d_66 (Conv2D) (None, 16, 16, 256) 524544
_________________________________________________________________
conv2d_67 (Conv2D) (None, 8, 8, 256) 1048832
_________________________________________________________________
flatten_11 (Flatten) (None, 16384) 0
_________________________________________________________________
dropout_33 (Dropout) (None, 16384) 0
_________________________________________________________________
dense_19 (Dense) (None, 512) 8389120
_________________________________________________________________
dense_20 (Dense) (None, 24) 12312
code:
model = Sequential()
model.add(Conv2D(64, kernel_size=4, strides=1, activation='relu', input_shape = (64,64,1),padding = 'same'))
model.add(Conv2D(64, kernel_size=4, strides=2, activation='relu',padding = 'same'))
model.add(Dropout(0.2))
model.add(Conv2D(128, kernel_size=4, strides=1, activation='relu',padding = 'same'))
model.add(Conv2D(128, kernel_size=4, strides=2, activation='relu',padding = 'same'))
model.add(Dropout(0.2))
model.add(Conv2D(256, kernel_size=4, strides=1, activation='relu',padding = 'same'))
model.add(Conv2D(256, kernel_size=4, strides=2, activation='relu',padding = 'same'))
model.add(Flatten())
model.add(Dropout(0.3))
model.add(Dense(512, activation='relu'))
model.add(Dense(24, activation='softmax'))
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
print(model.summary())
model.fit(x_train, y_train, validation_data=(x_test, y_test),batch_size=64,epochs=8)
dimensions of arrays used:
x_train: (3977, 64, 64, 1)
y_train: (3977, 1)
x_test: (995, 64, 64, 1)
y_test: (995, 1)
model.add(Dense(24, activation='softmax'))
at the end of your network so it expect your output is in shape of(24,)
and you are feedingy_train
with shape of(1,)
If I am not wrong you are trying to do classification for 24 class? – Krunal Vloss='sparse_categorical_crossentropy'
instead ofloss='categorical_crossentropy'
. – Vishnuvardhan Janapati