【发布时间】:2019-01-24 21:24:17
【问题描述】:
我正在尝试使用 keras 为我的神经网络创建以下指标:
其中 d=y_{pred}-y_{true}
y_{pred} 和 y_{true} 都是向量
使用以下代码:
将 keras.backend 导入为 K
def score(y_true, y_pred):
d=(y_pred - y_true)
if d<0:
return K.exp(-d/10)-1
else:
return K.exp(d/13)-1
用于编译我的模型:
model.compile(loss='mse', optimizer='adam', metrics=[score])
我收到以下错误代码,但我无法更正该问题。任何帮助将不胜感激。
raise TypeError("Using a
tf.Tensoras a Pythonboolis not 允许。 " "使用if t is not None:代替if t:来测试一个" "定义了张量,使用TensorFlow ops如"TypeError: 不允许将
tf.Tensor用作 Pythonbool。采用if t is not None:而不是if t:来测试是否定义了张量, 并使用 tf.cond 等 TensorFlow 操作来执行子图 以张量的值为条件。
【问题讨论】:
标签: python tensorflow neural-network keras