code: def serialize_loss(
      loss: tf.keras.losses.Loss, use_legacy_format=False
  ) -> Dict[str, Any]:
      """Serializes keras loss."""
      if (
          "use_legacy_format"
          in inspect.getfullargspec(tf.keras.losses.serialize).args
      ):
          cfg = tf.keras.losses.serialize(
              loss, use_legacy_format=use_legacy_format
          )
      else:
          cfg = tf.keras.losses.serialize(loss)
      # If a metric function (vs a class) is passed directly to compile, it
      # will be wrapped in a LossFunctionWrapper which is not deserializable.
      # If this happens, set the class name to the CamelCase from of the
      # function name since most keras loss functions have both forms.
      if (
          "class_name" in cfg
          and cfg["class_name"] == _LOSS_FUNCTION_WRAPPER
          and "config" in cfg
          and "name" in cfg["config"]
      ):
          cfg["class_name"] = _camel_case(cfg["config"]["name"])
      return cfg
  
imports: import inspect
  import math
  from typing import Any, Callable, Dict, Iterable, Iterator, List, Mapping, Optional, Tuple, Union
  import numpy
  import tensorflow
  from tensorflow_model_analysis import constants
  from tensorflow_model_analysis.api import types
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.proto import config_pb2
  from tensorflow_model_analysis.utils import util
  from tensorflow_metadata.proto.v0 import schema_pb2
label_desc: Use image node_id 5 for calling a global function with example usage: serialize_loss(loss, use_legacy_format) and returns: cfg