code: def _infer_single_example_keyed_processor(
      example: Union[Sequence, Any],
      class_labels_table: Optional["wandb.Table"] = None,
      possible_base_example: Optional[Union[Sequence, Any]] = None,
  ) -> Dict[str, Callable]:
      """Infers a processor from a single example.
  
      Infers a processor from a single example with optional class_labels_table
      and base_example. Base example is useful for cases such as segmentation masks
      """
      shape = _get_example_shape(example)
      processors: Dict[str, Callable] = {}
      if (
          class_labels_table is not None
          and len(shape) == 1
          and shape[0] == len(class_labels_table.data)
      ):
          np = wandb.util.get_module(
              "numpy",
              required="Infering processors require numpy",
          )
          # Assume these are logits
          class_names = class_labels_table.get_column("label")
  
          processors["max_class"] = lambda n, d, p: class_labels_table.index_ref(  # type: ignore
              np.argmax(d)
          )
          # TODO: Consider adding back if users ask
          # processors["min_class"] = lambda n, d, p: class_labels_table.index_ref(  # type: ignore
          #     np.argmin(d)
          # )
  
          values = np.unique(example)
          is_one_hot = len(values) == 2 and set(values) == {0, 1}
          if not is_one_hot:
              processors["score"] = lambda n, d, p: {
                  class_names[i]: d[i] for i in range(shape[0])
              }
      elif (
          len(shape) == 1
          and shape[0] == 1
          and (
              isinstance(example[0], int)
              or (hasattr(example, "tolist") and isinstance(example.tolist()[0], int))  # type: ignore
          )
      ):
          # assume this is a class
          if class_labels_table is not None:
              processors["class"] = lambda n, d, p: class_labels_table.index_ref(d[0]) if d[0] < len(class_labels_table.data) else d[0]  # type: ignore
          else:
              processors["val"] = lambda n, d, p: d[0]
      elif len(shape) == 1:
          np = wandb.util.get_module(
              "numpy",
              required="Infering processors require numpy",
          )
          # This could be anything
          if shape[0] <= 10:
              # if less than 10, fan out the results
              # processors["node"] = lambda n, d, p: {i: d[i] for i in range(shape[0])}
              processors["node"] = lambda n, d, p: [
                  d[i].tolist() if hasattr(d[i], "tolist") else d[i]
                  for i in range(shape[0])
              ]
          # just report the argmax and argmin
          processors["argmax"] = lambda n, d, p: np.argmax(d)
  
          values = np.unique(example)
          is_one_hot = len(values) == 2 and set(values) == {0, 1}
          if not is_one_hot:
              processors["argmin"] = lambda n, d, p: np.argmin(d)
      elif len(shape) == 2 and CAN_INFER_IMAGE_AND_VIDEO:
          if (
              class_labels_table is not None
              and possible_base_example is not None
              and shape == _get_example_shape(possible_base_example)
          ):
              # consider this a segmentation mask
              processors["image"] = lambda n, d, p: wandb.Image(
                  p,
                  masks={
                      "masks": {
                          "mask_data": d,
                          "class_labels": class_labels_table.get_column("label"),  # type: ignore
                      }
                  },
              )
          else:
              # consider this a 2d image
              processors["image"] = lambda n, d, p: wandb.Image(d)
      elif len(shape) == 3 and CAN_INFER_IMAGE_AND_VIDEO:
          # consider this an image
          processors["image"] = lambda n, d, p: wandb.Image(d)
      elif len(shape) == 4 and CAN_INFER_IMAGE_AND_VIDEO:
          # consider this a video
          processors["video"] = lambda n, d, p: wandb.Video(d)
  
      return processors
  
file_path: wandb/wandb/sdk/integration_utils/data_logging.py
imports: import sys
  from collections.abc import Sequence
  from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union
  import wandb
label_desc: Use image node_id 4 for calling a global function with example usage: _infer_single_example_keyed_processor(example, class_labels_table, possible_base_example) and returns: processors