使用Keras编译LSTM时出现断言错误

时间:2016-02-17 15:53:18

标签: python theano keras lstm recurrent-neural-network

我有以下代码:

max_features = 5000
maxlen = 140
model = Sequential()

model.add(Embedding(max_features, 128)) 
model.add(LSTM(128, activation = 'sigmoid', inner_activation =  'hard_sigmoid', return_sequences = False))
model.add(Dense(input_dim = 128, output_dim = 2, activation = 'softmax'))

optimizer = Adam(lr = 0.001, beta_1 = 0.9, beta_2 = 0.999, epsilon = 1e-8)
model.compile(loss = 'categorical_crossentropy', optimizer = optimizer)

model.fit(x_train, y_train, batch_size = 64, nb_epoch = 10, verbose = 2)

y_test_pred = model.predict_classes(x_test)

但每次我运行它时,我都会在行

处收到错误
model.compile(loss = 'categorical_crossentropy', optimizer = optimizer)

指出:

 AssertionError: The number of inputs given to the inner function of scan does not match the number of inputs given to scan.

有谁知道这意味着什么?

1 个答案:

答案 0 :(得分:0)

通过OP回答:

我已经解决了这个问题,事实证明它与过时的Theano版本有关。因此,如果您遇到此问题,请更新您的theano模块!