OlafenwaMoses / ImageAI

A python library built to empower developers to build applications and systems with self-contained Computer Vision capabilities
https://www.genxr.co/#products
MIT License
8.48k stars 2.18k forks source link

A target array with shape (6682, 2) was passed for an output of shape (None, 15, 2) while using as loss `categorical_crossentropy`. This loss expects targets to have the same shape as the output. #765

Open mrobotf opened 1 year ago

mrobotf commented 1 year ago

I try to build a BiLSTM network. It returns a

ValueError: A target array with shape (6682, 2) was passed for an output of shape (None, 15, 2) while using as loss categorical_crossentropy. This loss expects targets to have the same shape as the output. image

The structure is below:

model.add(Bidirectional(LSTM(int(n_units/2), return_sequences=True,
                                                 input_shape=(x.shape[0], x.shape[1]),
                                                 activation='tanh'),
                                        merge_mode='concat')
model.add(Dropout(0.2))
model.add(Dense(label_size,activation='softmax'))
model.compile(loss = 'categorical_crossentropy', optimizer = 'adam', metrics=['accuracy'])

n_units = 100
batch_size = 32
epochs = 3
output_dim = 20

below is dimension I print image