Keras值错误:层“sequential_1”的输入0与层不兼容:预期形状=(None,923679,63),找到的形状=(None,63)

ryoqjall  于 2023-10-19  发布在  其他
关注(0)|答案(1)|浏览(103)

我试图根据链接中发布的错误更改输入,但仍然收到相同的错误。

import tensorflow as tf
from tensorflow import keras
from keras.models import Sequential
from keras.layers import Dense, Embedding, LSTM, BatchNormalization, Bidirectional, LayerNormalization
from sklearn.model_selection import train_test_split
from keras.utils.np_utils import to_categorical
from keras import regularizers
import re
from keras.layers import Dropout
model=Sequential()
model.add(LSTM(units=100,return_sequences=True,input_shape=(923679,63)))
model.add(Dropout(0.2))
model.add(LSTM(units=100,return_sequences=True))
model.add(Dropout(0.2))
model.add(LSTM(units=100,return_sequences=True))
model.add(Dropout(0.2))
model.add(LSTM(units=100,return_sequences=False))
model.add(Dropout(0.2))
model.add(Dense(1,activation='sigmoid'))
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
print(model.summary())
X_train = np.reshape(X_train, (X_train.shape[0],X_train.shape[1]))
X_test = np.reshape(X_test, (X_test.shape[0],X_test.shape[1]))
Y_train = np.reshape(np.array(Y_train),(Y_train.shape[0]))
Y_test = np.reshape(np.array(Y_test),(Y_test.shape[0]))

enter image description here

model.fit(X_train,Y_train,epochs=50,batch_size=50, verbose=2, validation_data = (X_test, Y_test))

enter image description here

czfnxgou

czfnxgou1#

错误指向代码中的这一行。model.add(LSTM(units=100,return_sequences=True,input_shape=(923679,63)))
你必须给予形状为(无,63)所提到的错误。

相关问题