gpt4 book ai didi

python - Keras LSTM 神经网络 : TypeError: LSTM() missing 1 required positional argument: 'Y'

转载 作者:行者123 更新时间:2023-11-28 18:09:42 24 4
gpt4 key购买 nike

我正在尝试使用 Keras(2.2.0 版)和 TensorFlow(1.1.0 版)训练 LSTM 神经网络。我知道有更新的 TensorFlow 版本但不幸的是 I'm having some issues installing them .但是,我认为我的问题与 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

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

Traceback (most recent call last):

File "Main.py", line 208, in lstmModel = ann.LSTM(scaledTrainingX,trainingY)
File "ann.py", line 158, in LSTM model.add(LSTM(100))
TypeError: LSTM() missing 1 required positional argument: 'Y'

我找到了 this question在 StackOverflow 上,但那里建议的解决方案没有帮助,因为我没有使用生成器来训练我的网络。

如果您能帮助我们运行该网络,我们将不胜感激。非常感谢。

最佳答案

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

model.add(LSTM(100))

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

关于python - Keras LSTM 神经网络 : TypeError: LSTM() missing 1 required positional argument: 'Y' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51474015/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com