Python 无法使用dill:ed keras序列模型加载和预测

Python 无法使用dill:ed keras序列模型加载和预测,python,tensorflow,keras,predict,Python,Tensorflow,Keras,Predict,我有一个keras-LSTM型号: model = Sequential() model.add(Embedding(max_features, 128, input_length=maxlen)) model.add(LSTM(128, implenetation=0)) model.add(Dropout(0.5)) model.add(Dense(n_classes)) model.add(Activation('softmax')) model.compile(loss='categor

我有一个
keras-LSTM
型号:

model = Sequential()
model.add(Embedding(max_features, 128, input_length=maxlen))
model.add(LSTM(128, implenetation=0))
model.add(Dropout(0.5))
model.add(Dense(n_classes))
model.add(Activation('softmax'))
model.compile(loss='categorical_crossentropy', optimizer='sgd')
我已经训练过了,并把它扔进了一个莳萝档案。在同一台计算机上,稍后,我将尝试加载此模型,并使用
predict\u proba
对一些现在传入的数据进行预测。但我得到了一个错误:

TypeError: Cannot interpret feed_dict key as Tensor: Tensor Tensor("embedding_1_input:0", shape=(?, 53), dtype=int32) is not an element of this graph. 
我找到并尝试了这个方法。拟合和卸载模型:

### Creating and dumping model
model.fit(X, labels)
dill.dump(model, open(model_file, 'wb'))
加载并进行预测,从链接线程添加的行标记为
#added

model = dill.load(open(model_file, 'rb'))
model._make_prediction_function()           # added
graph = tf.get_default_graph()              # added
with graph.as_default():                    # added
    model.predict_proba(new_X)
但现在我得到了一个不同的错误:

`ValueError: Tensor Tensor("activation_1/Softmax:0", shape=(?, 18), dtype=float32) is not an element of this graph. 
我误解了如何实现此“解决方案”,或者是否有其他错误导致此问题?

为什么不按说明使用“model.save(filepath)”和“model=load\u model(filepath)”呢

如果您真的想使用dill来保存/加载图形,您能提供带有随机输入的完整代码吗