【问题标题】:LSTM Keras ValueErrorLSTM Keras ValueError
【发布时间】:2020-05-21 11:45:22
【问题描述】:

我的 LSTM 层不断收到此错误。

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

为什么是形状 (None, 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'])

【问题讨论】:

  • lstm 接收这种格式的输入... (n_sample, time_seq, feature_dim)... 你的 time_seq 是多少?
  • 什么是time_seq?抱歉,我对 LSTM 很陌生

标签: python-3.x keras lstm


【解决方案1】:

尝试改变这个:

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

到:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-07-23
    • 2020-07-08
    • 2021-03-08
    • 2016-12-07
    • 2018-11-06
    • 2020-05-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多