code: def agg_metric(inp):
      if isinstance(inp, Tensor):
          return inp.mean(dim=0)
      elif isinstance(inp, tuple):
          return tuple(agg_metric(elem) for elem in inp)
      return inp
  
imports: import warnings
  from collections import namedtuple
  from typing import Any, Callable, cast, Dict, Generic, List, NamedTuple, Optional, Tuple, TypeVar, Union
  from captum._utils.common import _expand_additional_forward_args, _format_additional_forward_args, _reduce_list
  from captum.attr import Max, Mean, Min, Summarizer
  from captum.log import log_usage
  from captum.robust._core.perturbation import Perturbation
  from torch import Tensor
label_desc: Use image node_id 1 for calling a global function with example usage: agg_metric(inp) and returns: inp, inp, tuple