class_docstr: Wrap a stateless metric function with the Mean metric.
  
  You could use this class to quickly build a mean metric from a function. The
  function needs to have the signature `fn(y_true, y_pred)` and return a
  per-sample loss array. `MeanMetricWrapper.result()` will return
  the average metric value across all samples seen so far.
  
  For example:
  
  ```python
  def mse(y_true, y_pred):
      return (y_true - y_pred) ** 2
  
  mse_metric = MeanMetricWrapper(fn=mse)
  ```
  
  Args:
      fn: The metric function to wrap, with signature
          `fn(y_true, y_pred, **kwargs)`.
      name: (Optional) string name of the metric instance.
      dtype: (Optional) data type of the metric result.
      **kwargs: Keyword arguments to pass on to `fn`.
class_docstr_tok: ["Wrap","a","stateless","metric","function","with","the","Mean","metric",".","You","could","use","this","class","to","quickly","build","a","mean","metric","from","a","function",".","The","function","needs","to","have","the","signature","`","fn","(","y_true",",","y_pred",")","`","and","return","a","per-sample","loss","array",".","`","MeanMetricWrapper.result","(",")","`","will","return","the","average","metric","value","across","all","samples","seen","so","far",".","For","example",":","``","`","python","def","mse","(","y_true",",","y_pred",")",":","return","(","y_true","-","y_pred",")","*","*","2","mse_metric","=","MeanMetricWrapper","(","fn=mse",")","``","`","Args",":","fn",":","The","metric","function","to","wrap",",","with","signature","`","fn","(","y_true",",","y_pred",",","*","*","kwargs",")","`",".","name",":","(","Optional",")","string","name","of","the","metric","instance",".","dtype",":","(","Optional",")","data","type","of","the","metric","result",".","*","*","kwargs",":","Keyword","arguments","to","pass","on","to","`","fn","`","."]
code: def __init__(self, fn, name=None, dtype=None, **kwargs):
      super().__init__(name=name, dtype=dtype)
      self._fn = fn
      self._fn_kwargs = kwargs
  
      # If we are wrapping a Keras loss, register the metric's
      # direction as "down" (needs to be minimized during training).
      if (
          self._fn in losses.ALL_OBJECTS
          or hasattr(self._fn, "__class__")
          and self._fn.__class__ in losses.ALL_OBJECTS
      ):
          self._direction = "down"
  
imports: from keras import backend
  from keras import initializers
  from keras import losses
  from keras import ops
  from keras.api_export import keras_export
  from keras.metrics.metric import Metric
  from keras.saving import serialization_lib
label_desc: Use image node_id 1 to create a new MeanMetricWrapper object from inherited base classes: Mean with example: obj = MeanMetricWrapper(fn, name, dtype)