Expected Dense_1 To Have 2 Dimensions, But Got Array With Shape (308, 1, 6)
I'm trying to use Conv1D for the first time for multiclass classification of time series data and my model keeps throwing this error when I use it. import numpy as np import os im
Solution 1:
So I noticed that even though I know there are 5 classes in this dataset as seen by the unique values obtained for y_all, for some reason Keras to_categorical thinks there are 6 classes.
# 384x6 y_all = keras.utils.to_categorical(y_all)
# 5 num_classes = np.unique(y_all).shape[0]
I don't know why that is. Keeping this in mind I changed this line of code and my model began to run:
model.add(Dense(num_classes, activation='softmax'))
to
model.add(Dense(num_classes+1, activation='softmax'))
I still don't know why to_categorical behaves this way. Anyone know?
Solution 2:
to_categorical(x)
in Keras will encode the given parameter into n
number of classes where n = max(x) + 1
, i.e. generally speaking from [0 , max(x)]
.
Post a Comment for "Expected Dense_1 To Have 2 Dimensions, But Got Array With Shape (308, 1, 6)"