Keras LSTM 神经网络:类型错误:LSTM() 缺少 1 个必需的位置参数:'Y'

Hag*_*ard 5 python neural-network lstm keras tensorflow

我正在尝试使用 Keras(2.2.0 版)和 TensorFlow(1.1.0 版)训练 LSTM 神经网络。我知道有更新的 TensorFlow 版本,但不幸的是我在安装它们时遇到了一些问题。但是,我不认为我的问题与 TensorFlow 版本有关。

这是我的 Keras 代码的样子:

[...] from keras.layers import Dense, Dropout, LeakyReLU, LSTM, Activation, Dense, Dropout, Input, Embedding

def LSTM(X,Y):
    inputDimension = len(X[0])
    inputSize = len(X)
    
    # create the model
    model = Sequential()
    model.add(Embedding(input_length=inputDimension,input_dim=inputDimension,output_dim=256))
    model.add(LSTM(100))
    model.add(Dropout(0.2))
    model.add(Dense(1, activation='sigmoid'))
    model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
    model.fit(X,Y,epochs=3,batch_size=64)
    return model
Run Code Online (Sandbox Code Playgroud)

每当我尝试运行它时,我都会收到以下错误消息:

回溯(最近一次调用最后一次):

文件“Main.py”,第 208 行,在 lstmModel = ann.LSTM(scaledTrainingX,trainingY)
文件“ann.py”,第 158 行,在 LSTM 模型中.add(LSTM(100))
TypeError: LSTM() missing 1 required位置参数:'Y'

我在 StackOverflow 上发现了这个问题,但建议的解决方案没有帮助,因为我没有使用生成器来训练我的网络。

任何帮助该网络运行的帮助将不胜感激。非常感谢。

rvi*_*nas 3

您创建模型的函数LSTM(X,Y)正在隐藏 Keras LSTM 层。所以当你打电话时:

model.add(LSTM(100))
Run Code Online (Sandbox Code Playgroud)

您确实正在调用您定义的函数。您需要将此函数重命名为其他名称。