【发布时间】:2020-11-27 11:39:21
【问题描述】:
你可以在下面找到我的自定义损失函数。
def custom_loss_function(y_true, y_pred):
y_pred_bool = tf.math.less_equal(y_pred, tf.constant(0.5))
y_pred_float = 1 - tf.cast(y_pred_bool, dtype=tf.int32)
y_true = tf.cast(y_true, dtype=tf.int32)
mask_bool_loss = tf.math.less(y_true, tf.constant(0))
mask_loss = 1 - tf.cast(mask_bool_loss, dtype=tf.int32)
mask = tf.math.reduce_min(mask_loss, axis=2)
y_multiply = tf.math.multiply(y_true, y_pred_float)
y = tf.math.reduce_sum(y_multiply, axis=2)
y_loss = 1 - y
y_loss = tf.math.multiply(y_loss, mask)
return y_loss
我知道tensorflow的一些函数是不可微分的,但我真的不知道哪些函数或者如何绕过它?对我有什么建议吗?
我收到此错误:
ValueError: No gradients provided for any variable: ['bidirectional_7/forward_lstm_7/lstm_cell_22/kernel:0'/, ...
【问题讨论】:
标签: tensorflow keras lstm loss