Keras 错误“您必须使用 dtype bool 为占位符张量‘bidirectional_1/keras_learning_phase’提供一个值" [英] Keras error "You must feed a value for placeholder tensor 'bidirectional_1/keras_learning_phase' with dtype bool"
本文介绍了Keras 错误“您必须使用 dtype bool 为占位符张量‘bidirectional_1/keras_learning_phase’提供一个值"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到以下代码片段的以下错误:
I get the following error for the code snippet below:
您必须为占位符张量提供一个值'bidirectional_1/keras_learning_phase' 与 dtype bool
You must feed a value for placeholder tensor 'bidirectional_1/keras_learning_phase' with dtype bool
如果我添加 dropout 层 model.add(Dropout(dropout))
,它会起作用.有谁知道为什么?后端是Tensorflow,Keras 2.0.1
If I add the dropout layer model.add(Dropout(dropout))
, it works. Anyone knows why? The back-end is Tensorflow, Keras 2.0.1
def prep_model1(embedding_layer1, embedding_layer2, dropout=0.5):
model0 = Sequential()
model0.add(embedding_layer1)
model0.add(Bidirectional(LSTM(128, return_sequences=False, dropout=dropout)))
model1 = Sequential()
model1.add(embedding_layer2)
model1.add(Bidirectional(LSTM(128, return_sequences=False, dropout=dropout)))
model = Sequential()
model.add(Merge([model0, model1], mode='concat', concat_axis=1))
#model.add(Dropout(dropout))
model.add(Dense(1, activation='sigmoid'))
return model
推荐答案
尝试导入 K 并在您的模型之前设置学习阶段.
Try to import K and set learning phase before your model.
from keras import backend as K
K.set_learning_phase(1) #set learning phase
来自这个问题
这篇关于Keras 错误“您必须使用 dtype bool 为占位符张量‘bidirectional_1/keras_learning_phase’提供一个值"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文