使用K.tf.math.round时实现自定义损失函数Keras时出错

时间:2019-07-29 10:56:17

标签: tensorflow machine-learning keras loss-function tf.keras

def custom_loss():
    def loss(y_true, y_pred):
        y_pred_new = K.tf.math.round(y_pred) #error thrown because of this statement
        # other statements #
        y_new = K.tf.math.subtract(y_pred_new, y_true)
        # other statements #
    return K.tf.math.reduce_sum(y_new)
return loss
  

我要构建的损失函数涉及四舍五入   最终乙状结肠层的预测为0或1。

K.tf.math.round显示以下错误:

  

ValueError:操作具有None用于渐变。请确定   您所有的操作都定义了渐变(即   可区分的)。不带渐变的常见操作:K.argmax,K.round,   埃瓦尔。

如何替换张量的舍入功能?或对此可以做什么?

0 个答案:

没有答案
相关问题