From de5d18b8e88227404127cef9ca9177dbb010f863 Mon Sep 17 00:00:00 2001 From: Gabriel Rasskin <43894452+grasskin@users.noreply.github.com> Date: Tue, 23 Jul 2024 17:09:19 -0400 Subject: [PATCH] Add clear deprecation error message for add_metric() (#20034) * Add clear deprecation error message for add_metric() * Message formatting * Specify compile is a model method * Remove not implemented test for add_metric --- keras/src/layers/layer.py | 5 ++++- keras/src/layers/layer_test.py | 1 - 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/keras/src/layers/layer.py b/keras/src/layers/layer.py index 575457cb066..a7383c97441 100644 --- a/keras/src/layers/layer.py +++ b/keras/src/layers/layer.py @@ -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. diff --git a/keras/src/layers/layer_test.py b/keras/src/layers/layer_test.py index 81378535c81..99b842163e6 100644 --- a/keras/src/layers/layer_test.py +++ b/keras/src/layers/layer_test.py @@ -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",