Keras: Error when checking target: expected dense_10 to have 2 dimensions, but got array with shape (2560, 69, 3)

Created on 29 Jan 2018  路  5Comments  路  Source: keras-team/keras

Tried posting on the slack channel and StackOverflow but no answers received, hence, posting here:

I am trying to build a model for sequence tag classification. X_train is of shape(2560, 69), Y_train is (2560, 69, 3)This is what the architecture looks like:

m = Sequential([
                Embedding(vocab_size + 1, embedding_dim, weights=[embedding_matrix], 
                                        input_length=max_len, trainable=False),           
                Bidirectional(LSTM(150, activation='relu')),           
                Dense(150, activation='relu'), 
                Dense(max_len, activation='sigmoid')         
])

The loss is categorical_crossentropy. When I try to fit my data, this is the error thrown:聽
Error when checking target: expected dense_10 to have 2 dimensions, but got array with shape (2560, 69, 3)

I tried adding a Flatten layer before the first Dense layer but that results in聽Input 0 is incompatible with layer flatten_3: expected min_ndim=3, found ndim=2

I am not sure how to fix the dimensions.

User error

Most helpful comment

Your targets should have shape (num_samples, num_classes). You're passing an array of shape (2560, 69, 3).

All 5 comments

Your targets should have shape (num_samples, num_classes). You're passing an array of shape (2560, 69, 3).

This makes sense and that is what I was following before I ran into the issue.

But the paper states that the sentence is IOB encoded and then converted to one hot (Section 3.2) which makes the output a 3D vector instead of 2D.

FYR:
screenshot 2018-02-05 12 54 53

Is there something I am misinterpreting?

(I understand that this might not be the right place to post this but I haven't had any luck with other forums)

@MrDHat - Did you get this answered?

@MrDHat ,,did you solve this error? i am having the same problem...don't know what to do!!

HOW CAN I SOLVE THIS ERROR? any suggestion

for (root, dirs, files) in os.walk('images/test'):
if files:
for f in files:
print(f)
path = os.path.join(root, f)
image = cv2.imread(path)
image = detect_image(image, yolo, all_classes)
cv2.imwrite('images/res/' + f, image)

image = cv2.resize(img, (416, 416),
interpolation=cv2.INTER_CUBIC)
image = np.array(image, dtype='float32')
image /= 255.
image = np.expand_dims(image, axis=0)

return image

ValueError: Error when checking : expected input_1 to have shape (608, 608, 3) but got array with shape (416, 416, 3)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

farizrahman4u picture farizrahman4u  路  3Comments

LuCeHe picture LuCeHe  路  3Comments

kylemcdonald picture kylemcdonald  路  3Comments

MarkVdBergh picture MarkVdBergh  路  3Comments

harishkrishnav picture harishkrishnav  路  3Comments