ValueError: Input 0 of layer sequential_17 is incompatible w



我正在尝试使用NSL-KDD数据集构建一个循环神经网络。当我运行下面的代码时,我不断得到ValueError:层sequential_17的输入0与层不兼容:预期的ndim=3,发现ndim=2。收到完整形状:[None, 121]. 我不知道为什么,我可能和输入形状有关?我不确定,因为我对python还是个新手。如果有帮助的话,我也做了所有的数据预处理。

from keras.utils import np_utils
from keras.models import Sequential
from keras.preprocessing import sequence
from keras.layers import Dense, Dropout, Activation, Embedding
from keras.layers import LSTM, SimpleRNN, GRU
from keras.utils import np_utils
from keras import callbacks
from keras.callbacks import ModelCheckpoint, EarlyStopping, ReduceLROnPlateau, CSVLogger
import tensorflow.keras as keras
print (X_train.shape),(y_train2.shape)
(125973, 121)
(None, (125973,))
batch_size = 99
epcochs = 100
model = Sequential()
model.add(LSTM(10,batch_input_shape =(None, 99, 1), return_sequences=True ))
model.add(Dropout(0.01))
model.add(LSTM(10,return_sequences=True))
model.add(Dropout(0.01))
model.add(LSTM(10,return_sequences=False))
model.add(Dropout(0.01))
model.add(Dense(1))
model.add(Activation('sigmoid'))
model.compile(loss='binary_crossentropy', optimizer=keras.optimizers.Adam() , metrics=['accuarcy'])
fit=model.fit(X_train, y_train2, batch_size=batch_size, epochs=100, validation_data=(X_test, y_test2))
loss, accuracy = model.evaluate(X_test, y_test1)
print("nLoss: %.2f, Accuracy: %.2f%%" % (loss, accuracy*100))
y_pred = model>predict_classes(X_test)

try this

numpy.expand_dims(X_train, axis=0)

相关内容

  • 没有找到相关文章

最新更新