keras icon indicating copy to clipboard operation
keras copied to clipboard

Keras custom loss function considering previous prediction and label

Open minsung-k opened this issue 1 year ago • 1 comments

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

minsung-k avatar Dec 25 '23 04:12 minsung-k

Hi @minsung-k , Could you please close this issue as it is duplicate of #19004.

SuryanarayanaY avatar Jan 03 '24 09:01 SuryanarayanaY

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.

github-actions[bot] avatar Apr 26 '24 01:04 github-actions[bot]

This issue was closed because it has been inactive for 28 days. Please reopen if you'd like to work on this further.

github-actions[bot] avatar May 10 '24 01:05 github-actions[bot]

Are you satisfied with the resolution of your issue? Yes No

google-ml-butler[bot] avatar May 10 '24 01:05 google-ml-butler[bot]