code: def average(x, per_image=False, class_weights=None, **kwargs):
      backend = kwargs["backend"]
      if per_image:
          x = backend.mean(x, axis=0)
      if class_weights is not None:
          x = x * class_weights
      return backend.mean(x)
  
file_path: segmentation_models/segmentation_models/base/functional.py
label_desc: Use image node_id 5 for calling a global function with example usage: average(x, per_image, class_weights) and returns: backend