code: def _to_dict(params):
      if isinstance(params, dict):
          return params
  
      # Handle some cases where params is not a dictionary
      # by trying to convert it into a dictionary
      meta = inspect.getmodule(params)
      if meta:
          is_tf_flags_module = (
              isinstance(params, types.ModuleType)
              and meta.__name__ == "tensorflow.python.platform.flags"
          )
          if is_tf_flags_module or meta.__name__ == "absl.flags":
              params = params.FLAGS
              meta = inspect.getmodule(params)
  
      # newer tensorflow flags (post 1.4) uses absl.flags
      if meta and meta.__name__ == "absl.flags._flagvalues":
          params = {name: params[name].value for name in dir(params)}
      elif not hasattr(params, "__dict__"):
          raise TypeError(
              "config must be a dict or have a __dict__ attribute."
          )
      elif "__flags" in vars(params):
          # for older tensorflow flags (pre 1.4)
          if not "__parsed" not in vars(params):
              params._parse_flags()
          params = vars(params)["__flags"]
      else:
          # params is a Namespace object (argparse)
          # or something else
          params = vars(params)
  
      # assume argparse Namespace
      return params
  
imports: import inspect
  import types
  from wandb.errors import UsageError
  from .lib import config_util
label_desc: Use image node_id 2 for calling a global function with example usage: _to_dict(params) and returns: params, params