keras
keras copied to clipboard
Keras custom loss function considering previous prediction and label
Hi, I would like to ask the way to build a custom loss function which considering previous prediction and label.
Here's the demo code.
def model_loss(prev_y_true, prev_y_pred):
@tf.function
def my_loss(y_true,y_pred):
violation_term = tf.cast(tf.math.maximum( (y_pred - prev_output) , 0), tf.float64)
if prev_y_true < y_true:
return tf.reduce_mean(tf.square(y_true - y_pred), axis=-1)
else: return tf.reduce_mean(tf.square(y_true - y_pred), axis=-1) + (violation_term ** 2)
return my_loss
Please let me know the way to find prev_y_true and prev_y_pred
Best, Min
Hi @minsung-k , Could you please close this issue as it is duplicate of #19004.
This issue is stale because it has been open for 14 days with no activity. It will be closed if no further activity occurs. Thank you.
This issue was closed because it has been inactive for 28 days. Please reopen if you'd like to work on this further.