'method' object has no attribute '_from_serialized' Error when using custom metrics in a class

Is this a bug? This is working before…
I have a class that compiles a model and im using custom metrics. Now, its not compiling. I’m getting

AttributeError: 'method' object has no attribute '_from_serialized'

Here’s a pseudo code:

def compile(self):
        self.model.compile(optimizer = optimizer, loss = self._custom_loss, metrics= [self._custom_metric])

def _custom_metric(self, y_target, y_predicted):
      some_val = *some_val
      return some_val

I’m looking forward to your response.

Do you have a very minimal standalone example or Colab to reproduce this?

What is your TF version?

I have not solved it. BUt I faced a similar error. I patched it by downgrading to tf version 2.4.0

For new TF/Keras versions check: