code: def update(
      self,
      prediction: Union[Tensor, Dict],
      target: Union[Tensor, Dict],
      extras: Optional[Dict[str, Any]] = {},
      batch_size: Optional[int] = 1,
  ) -> None:
      prediction = self.preprocess_predictions(prediction)
      target = self.preprocess_targets(target)
  
      metric = self.gather_metrics(prediction, target, extras)
  
      if isinstance(metric, Dict):
          # The values should be summed over all existing workers
          metric = {
              k: self._aggregate_ddp_sum(v * batch_size)
              for k, v in metric.items()
          }
          if self.value is None:
              self.value = metric
          else:
              for k, v in metric.items():
                  self.value[k] += v
  
      elif isinstance(metric, Tensor):
          if self.value is None:
              self.value = 0
  
          # The value should be summed over all existing workers
          self.value += self._aggregate_ddp_sum(metric * batch_size)
      else:
          raise ValueError(
              "gather_metrics should return a Tensor or a Dict containing Tensors. Got {}: {}".format(
                  metric.__class__, metric
              )
          )
  
      # The count should be summed over all existing workers
      self.count += self._aggregate_ddp_sum(batch_size)
  
imports: import abc
  import argparse
  from numbers import Number
  from typing import Any, Dict, List, Optional, Tuple, Union
  import numpy
  import torch
  from torch import Tensor
  from utils import logger
  from utils.tensor_utils import all_gather_list, reduce_tensor_sum, tensor_to_python_float
label_desc: Use image node_id 4 for calling the AverageMetric obj's underlying member method code with example usage: obj.update(prediction, target, extras, batch_size) without return types