code: def get_class_ids_from_numpy_labels(
      labels: t.Sequence[t.Union[np.ndarray, int]], task_type: TaskType
  ) -> t.Dict[int, int]:
      """Return the number of images containing each class_id.
  
      Returns
      -------
      Dict[int, int]
          A dictionary mapping each class_id to the number of images containing it.
      """
      if task_type == TaskType.CLASSIFICATION:
          return Counter(labels)
      elif task_type == TaskType.OBJECT_DETECTION:
          class_ids_per_image = [
              label[:, 0]
              for label in labels
              if label is not None and len(label.shape) == 2
          ]
          return (
              Counter(np.hstack(class_ids_per_image))
              if len(class_ids_per_image) > 0
              else {}
          )
      elif task_type == TaskType.SEMANTIC_SEGMENTATION:
          labels_per_image = [
              np.unique(label) for label in labels if label is not None
          ]
          return Counter(np.hstack(labels_per_image))
      else:
          raise ValueError(f"Unsupported task type: {task_type}")
  
imports: import random
  import sys
  import typing
  from collections import Counter
  from enum import Enum
  from numbers import Number
  import numpy
  from typing_extensions import NotRequired, TypedDict
  from deepchecks.core.errors import DatasetValidationError
  from deepchecks.utils.logger import get_logger
label_desc: Use image node_id 4 for calling a global function with example usage: get_class_ids_from_numpy_labels(labels, task_type) and returns: Counter, unknown, Counter