Skip to content

Commit

Permalink
Add clear deprecation error message for add_metric() (#20034)
Browse files Browse the repository at this point in the history
* Add clear deprecation error message for add_metric()

* Message formatting

* Specify compile is a model method

* Remove not implemented test for add_metric
  • Loading branch information
grasskin authored Jul 23, 2024
1 parent 3ac43b1 commit de5d18b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 4 additions & 1 deletion keras/src/layers/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,10 @@ def _untrack_variable(self, variable):

def add_metric(self, *args, **kwargs):
# Permanently disabled
raise self._not_implemented_error(self.add_metric)
raise NotImplementedError(
"Layer `add_metric()` method is deprecated"
" add your metric in `Model.compile(metrics=[...]).`"
)

def count_params(self):
"""Count the total number of scalars composing the weights.
Expand Down
1 change: 0 additions & 1 deletion keras/src/layers/layer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ def call(self, x, bool_arg):
@parameterized.named_parameters(
("call", "call", None),
("compute_output_shape", "compute_output_shape", None),
("add_metric", "add_metric", None),
(
"quantized_build",
"quantized_build",
Expand Down

0 comments on commit de5d18b

Please sign in to comment.