LSTM Keras ValueError



我在 LSTM 层中不断收到此错误。

ValueError: Error when checking input: expected lstm_input to have 3 dimensions, but got array with shape (None, 3)

为什么形状是(无,3(,我该如何解决这个问题?另外,您如何判断数组的大小? 这是我的模型代码:

class RNN():
def __init__(self, data, labels):
#get data for the model
self.SAMPLEAMOUT = 5
self.data = np.array(data)
self.labels = labels
print(self.data.shape)
#initialize model
self.model = Sequential()
self.model.add(LSTM(3, input_shape=self.data.shape))
self.model.add(Dense(9, activation='relu'))
self.model.add(Dense(1, activation='relu'))
self.model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
accuracy=['accuracy', 'loss'])

尝试更改以下内容:

self.model.add(LSTM(3, input_shape=self.data.shape))

自:

self.model.add(LSTM(3, input_shape=self.data.shape[1:]))

相关内容

最新更新