docstr: Updates all the metrics after a batch.
  
  :param pred_label: predictions coming from a model (must be a Tensor or a Dict of Tensors)
  :param target_label: GT labels (Tensor or a Dict of Tensors)
  :param extras: Optional Dict containing extra info, usually Loss and GradNorm
                 e.g. {"loss": loss_value, "grad_norm": gradient_norm}
  :param batch_time: Optional time it took to run through the batch
  :param n: batch size (to be used in averaging the numbers correctly)
docstr_tok: ["Updates","all","the","metrics","after","a","batch",".",":","param","pred_label",":","predictions","coming","from","a","model","(","must","be","a","Tensor","or","a","Dict","of","Tensors",")",":","param","target_label",":","GT","labels","(","Tensor","or","a","Dict","of","Tensors",")",":","param","extras",":","Optional","Dict","containing","extra","info",",","usually","Loss","and","GradNorm","e.g",".","{","``","loss","''",":","loss_value",",","``","grad_norm","''",":","gradient_norm","}",":","param","batch_time",":","Optional","time","it","took","to","run","through","the","batch",":","param","n",":","batch","size","(","to","be","used","in","averaging","the","numbers","correctly",")"]
code: def update(
      self,
      pred_label: Union[Tensor, Dict],
      target_label: Union[Tensor, Dict],
      extras: Optional[Dict[str, Any]] = None,
      batch_time: Optional[float] = 0.0,
      batch_size: Optional[int] = 1,
  ) -> None:
      """
      Updates all the metrics after a batch.
  
      :param pred_label: predictions coming from a model (must be a Tensor or a Dict of Tensors)
      :param target_label: GT labels (Tensor or a Dict of Tensors)
      :param extras: Optional Dict containing extra info, usually Loss and GradNorm
                     e.g. {"loss": loss_value, "grad_norm": gradient_norm}
      :param batch_time: Optional time it took to run through the batch
      :param n: batch size (to be used in averaging the numbers correctly)
      """
      for metric_name, metric in self.metric_dict.items():
          try:
              metric.update(
                  prediction=pred_label,
                  target=target_label,
                  extras=extras,
                  batch_size=batch_size,
              )
          except Exception as e:
              traceback.print_exc()
              logger.error(
                  "Caught an error while updating metric {}: {}".format(
                      metric_name, e
                  )
              )
  
      self.batch_time += batch_time
      self.batch_counter += 1
  
imports: import argparse
  import sys
  import time
  import traceback
  from numbers import Number
  from typing import Any, Dict, List, Optional, Union
  import numpy
  import torch
  from torch import Tensor
  from metrics import METRICS_REGISTRY
  from metrics.metric_base import BaseMetric
  from utils import logger
  from utils.object_utils import apply_recursively, flatten_to_dict
label_desc: Use image node_id 2 for calling the Statistics obj's underlying member method code with example usage: obj.update(pred_label, target_label, extras, batch_time, batch_size) without return types