code: def to_dict(clazz):
      """The :func:`to_dict` decorator is used to wrap either a :class:`.Metric` class or a :class:`.Metric` instance with
      a :class:`.ToDict` instance. The result is that future output will be wrapped in a `dict[name, value]`.
  
      Example: ::
  
          >>> from torchbearer import metrics
  
          >>> @metrics.lambda_metric('my_metric')
          ... def my_metric(y_pred, y_true):
          ...     return y_pred + y_true
          ...
          >>> my_metric.process({'y_pred':4, 'y_true':5})
          9
  
          >>> @metrics.to_dict
          ... @metrics.lambda_metric('my_metric')
          ... def my_metric(y_pred, y_true):
          ...     return y_pred + y_true
          ...
          >>> my_metric.process({'y_pred':4, 'y_true':5})
          {'my_metric': 9}
  
      Args:
          clazz: The class to *decorate*
  
      Returns:
          A :class:`.ToDict` instance or a :class:`.ToDict` wrapper of the given class
      """
      if inspect.isclass(clazz):
  
          class Wrapper(ToDict):
              __doc__ = clazz.__doc__
  
              def __init__(self, *args, **kwargs):
                  super(Wrapper, self).__init__(clazz(*args, **kwargs))
  
          Wrapper.__name__ = clazz.__name__
          return Wrapper
      else:
          return ToDict(clazz)
  
file_path: torchbearer/torchbearer/metrics/decorators.py
imports: import inspect
  from torchbearer.metrics import EpochLambda, BatchLambda, ToDict, Mean, MetricTree, Std, Var, RunningMean
  from .metrics import add_default
label_desc: Use image node_id 3 for calling a global function with example usage: to_dict(clazz) and returns: Wrapper, ToDict