Skip to content

Conversation

adar21a
Copy link
Contributor

@adar21a adar21a commented May 11, 2025

@codecov-commenter
Copy link

codecov-commenter commented May 11, 2025

Codecov Report

Attention: Patch coverage is 98.27586% with 1 line in your changes missing coverage. Please review.

Project coverage is 82.60%. Comparing base (dfaca0e) to head (6ff2549).
Report is 11 commits behind head on master.

Files with missing lines Patch % Lines
keras/src/callbacks/monitor_callback.py 97.61% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #21275      +/-   ##
==========================================
+ Coverage   82.57%   82.60%   +0.02%     
==========================================
  Files         564      565       +1     
  Lines       54677    54772      +95     
  Branches     8500     8508       +8     
==========================================
+ Hits        45152    45243      +91     
- Misses       7435     7439       +4     
  Partials     2090     2090              
Flag Coverage Δ
keras 82.41% <98.27%> (+0.02%) ⬆️
keras-jax 63.55% <98.27%> (-0.06%) ⬇️
keras-numpy 58.70% <48.27%> (-0.04%) ⬇️
keras-openvino 33.13% <25.86%> (+0.08%) ⬆️
keras-tensorflow 63.96% <98.27%> (-0.07%) ⬇️
keras-torch 63.62% <98.27%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@fchollet fchollet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

@@ -197,6 +183,44 @@ def __init__(
f"filepath={self.filepath}"
)

def _set_monitor_op(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we refactor this logic into a standalone function that we could reuse across all callbacks that need this functionality?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a MonitorCallback base class for all the callbacks that use this functionality (currently EarlyStopping, ReduceLROnPlateau and ModelCheckpoint). This ensures consistent behavior across callbacks and reduces code duplication.

from keras.src.trainers import compile_utils


@keras_export("keras.callbacks.MonitorCallback")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The refactoring into a shared base class makes sense, but please do not export it to the public API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it. However, I do think it could be useful as a public API — perhaps in a follow-up PR with some adjustments. It would be helpful for users who want to create custom callbacks that monitor a metric — for example, plotting something whenever the loss decreases.

@adar21a adar21a requested a review from fchollet May 20, 2025 05:54
Copy link
Collaborator

@fchollet fchollet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you for the updates!

@google-ml-butler google-ml-butler bot added kokoro:force-run ready to pull Ready to be merged into the codebase labels May 20, 2025
@fchollet fchollet merged commit 37a0920 into keras-team:master May 20, 2025
7 checks passed
@google-ml-butler google-ml-butler bot removed awaiting review ready to pull Ready to be merged into the codebase kokoro:force-run labels May 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants