简体   繁体   中英

Keras CNN error Input 0 of layer conv1d_13 is incompatible with the layer: : expected min_ndim=3, found ndim=2

I have dataset 9 columns. Column 1-8 is feature, column 9 is class of dataset. I use CNN to classify like this code.

model = Sequential()
model.add(Conv1D(64, 2, activation="relu", input_shape=(8,1)))
model.add(Flatten())

model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
model.fit(X, y, epochs=150, batch_size=10)

It show error like this.

ValueError: Input 0 of layer conv1d_13 is incompatible with the layer: : expected min_ndim=3, found ndim=2. Full shape received: (None, 8)

How to fix it?

Try:

X = X[..., None]

to add an additional dimension to X . See also this .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM