code: def get_target_formatter(
      targets: List[Any],
      labels: Optional[List[str]] = None,
      num_classes: Optional[int] = None,
      add_background: bool = False,
  ) -> TargetFormatter:
      """Get the ``TargetFormatter`` object to use for the given targets.
  
      Args:
          targets: The list of targets to format.
          labels: Optionally provide ``labels`` / ``num_classes`` instead of inferring them.
          num_classes: Optionally provide ``labels`` / ``num_classes`` instead of inferring them.
          add_background: If ``True``, a background class will be inserted as class zero if ``labels`` and
                  ``num_classes`` are being inferred.
  
      Returns:
          The target formatter to use when formatting targets.
  
      """
      targets = _as_list(targets)
      target_formatter_type: Type[TargetFormatter] = reduce(
          _resolve_target_formatter,
          [_get_target_formatter_type(target) for target in targets],
      )
      if labels is None and num_classes is None:
          labels, num_classes = _get_target_details(
              targets, target_formatter_type
          )
          if add_background:
              labels = (
                  ["background"] + labels
                  if labels is not None
                  else labels
              )
              num_classes = (
                  num_classes + 1
                  if num_classes is not None
                  else num_classes
              )
      return target_formatter_type(
          labels=labels, num_classes=num_classes
      )
  
imports: from dataclasses import dataclass
  from functools import reduce
  from typing import Any, ClassVar, Dict, List, Optional, Tuple, Type, Union, cast
  import numpy
  import torch
  from torch import Tensor
  from flash.core.data.utilities.sort import sorted_alphanumeric
  from flash.core.utilities.imports import _TOPIC_CORE_AVAILABLE
label_desc: Use image node_id 7 for calling a global function with example usage: get_target_formatter(targets, labels, num_classes, add_background) and returns: target_formatter_type