code: def mean(clazz=None, dim=None):
      """The :func:`mean` decorator is used to add a :class:`.Mean` to the :class:`.MetricTree` which will will output a
      mean value at the end of each epoch. At build time, if the inner class is not a :class:`.MetricTree`, one will be
      created. The :class:`.Mean` will also be wrapped in a :class:`.ToDict` for simplicity.
  
      Example: ::
  
          >>> import torch
          >>> from torchbearer import metrics
  
          >>> @metrics.mean
          ... @metrics.lambda_metric('my_metric')
          ... def metric(y_pred, y_true):
          ...     return y_pred + y_true
          ...
          >>> metric.reset({})
          >>> metric.process({'y_pred':torch.Tensor([2]), 'y_true':torch.Tensor([2])}) # 4
          {}
          >>> metric.process({'y_pred':torch.Tensor([3]), 'y_true':torch.Tensor([3])}) # 6
          {}
          >>> metric.process({'y_pred':torch.Tensor([4]), 'y_true':torch.Tensor([4])}) # 8
          {}
          >>> metric.process_final()
          {'my_metric': 6.0}
  
      Args:
          clazz: The class to *decorate*
          dim (int, tuple): See :class:`.Mean`
  
      Returns:
          A :class:`.MetricTree` with a :class:`.Mean` appended or a wrapper class that extends :class:`.MetricTree`
      """
      if clazz is None:
  
          def decorator(clazz):
              return mean(clazz, dim=dim)
  
          return decorator
  
      return _wrap_and_add_to_tree(
          clazz, lambda metric: ToDict(Mean(metric.name, dim=dim))
      )
  
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 5 for calling a global function with example usage: mean(clazz, dim) and returns: _wrap_and_add_to_tree, decorator, mean