Losses - Keras
keras.io › api › lossesGradientTape as tape: # Forward pass. logits = model (x) # Loss value for this batch. loss_value = loss_fn (y, logits) # Add extra loss terms to the loss value. loss_value += sum (model. losses) # Update the weights of the model to minimize the loss value. gradients = tape. gradient (loss_value, model. trainable_weights) optimizer. apply_gradients (zip (gradients, model. trainable_weights))