Skip to content

Update layer.py add_metric error message #21290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions keras/src/layers/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1417,8 +1417,11 @@ def _untrack_variable(self, variable):
def add_metric(self, *args, **kwargs):
# Permanently disabled
raise NotImplementedError(
"Layer `add_metric()` method is deprecated"
" add your metric in `Model.compile(metrics=[...]).`"
"Layer `add_metric()` method is deprecated. "
"Add your metric in `Model.compile(metrics=[...])`, "
"or create metric trackers in init() or build() "
"when subclassing the layer or model, then call "
"`metric.update_state()` whenever necessary."
)

def count_params(self):
Expand Down