Python Keras LSTM神经网络:TypeError:LSTM()缺少1个必需的位置参数:';Y';
我正在尝试使用Keras(版本2.2.0)和TensorFlow(版本1.1.0)来训练LSTM神经网络。我知道有更新的TensorFlow版本,但不幸的是。然而,我不相信我的问题与TensorFlow版本有关 我的Keras代码是这样的:Python Keras LSTM神经网络:TypeError:LSTM()缺少1个必需的位置参数:';Y';,python,tensorflow,neural-network,keras,lstm,Python,Tensorflow,Neural Network,Keras,Lstm,我正在尝试使用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):
[...] 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
每当我尝试运行它时,都会出现以下错误消息:
回溯(最近一次呼叫最后一次):
文件“Main.py”,第208行,在lstmModel=ann.LSTM(scaledTrainingX,trainingY)中文件“ann.py”,第158行,在LSTM model.add(LSTM(100))中
TypeError:LSTM()缺少1个必需的位置参数:“Y” 我在StackOverflow上找到了,但解决方案表明没有帮助,因为我没有使用生成器来训练我的网络 我们将非常感谢您对该网络运行的任何帮助。非常感谢。创建模型的函数
LSTM(X,Y)
正在对Keras LSTM层进行阴影处理。所以当你打电话时:
model.add(LSTM(100))
您确实在调用您定义的函数。您需要将此函数重命名为其他函数。您能告诉我们完整的回溯错误吗?哦,天哪。。。这有点尴尬,但你完全正确。非常感谢你。但是,现在我得到了以下消息:“TypeError:while_loop()得到了一个意外的关键字参数‘maximum_iterations’”,尽管这个参数没有在任何地方给出。不客气。我不知道你为什么会犯这个错误。如果你发布一个新的问题和代码以及完整的回溯,我可能会帮上忙。非常感谢你的提议。然而,我最终设法将TensorFlow版本更新到1.8.0,问题似乎消失了。