code: def model_metadata(
      model, include_optimizer=True, require_config=True
  ):
      """Returns a dictionary containing the model metadata."""
      from keras import __version__ as keras_version
  
      model_config = {"class_name": model.__class__.__name__}
      try:
          model_config["config"] = model.get_config()
      except NotImplementedError as e:
          if require_config:
              raise e
  
      metadata = dict(
          keras_version=str(keras_version),
          backend=backend.backend(),
          model_config=model_config,
      )
      if getattr(model, "optimizer", False) and include_optimizer:
          if model.compiled:
              training_config = model._compile_config.config
              training_config.pop(
                  "optimizer", None
              )  # Handled separately.
              metadata["training_config"] = _serialize_nested_config(
                  training_config
              )
              optimizer_config = {
                  "class_name": object_registration.get_registered_name(
                      model.optimizer.__class__
                  ),
                  "config": model.optimizer.get_config(),
              }
              metadata["training_config"][
                  "optimizer_config"
              ] = optimizer_config
      return metadata
  
imports: import json
  import threading
  import tree
  from absl import logging
  from keras import backend
  from keras import layers
  from keras import losses
  from keras import metrics
  from keras import models
  from keras import optimizers
  from keras.legacy.saving import serialization
  from keras.saving import object_registration
label_desc: Use image node_id 2 for calling a global function with example usage: model_metadata(model, include_optimizer, require_config) and returns: metadata