code: def partition_dataset_classes(
      data: Sequence,
      classes: Sequence[int],
      ratios: Sequence[float] | None = None,
      num_partitions: int | None = None,
      shuffle: bool = False,
      seed: int = 0,
      drop_last: bool = False,
      even_divisible: bool = False,
  ):
      """
      Split the dataset into N partitions based on the given class labels.
      It can make sure the same ratio of classes in every partition.
      Others are same as :py:class:`monai.data.partition_dataset`.
  
      Args:
          data: input dataset to split, expect a list of data.
          classes: a list of labels to help split the data, the length must match the length of data.
          ratios: a list of ratio number to split the dataset, like [8, 1, 1].
          num_partitions: expected number of the partitions to evenly split, only works when no `ratios`.
          shuffle: whether to shuffle the original dataset before splitting.
          seed: random seed to shuffle the dataset, only works when `shuffle` is True.
          drop_last: only works when `even_divisible` is False and no ratios specified.
              if True, will drop the tail of the data to make it evenly divisible across partitions.
              if False, will add extra indices to make the data evenly divisible across partitions.
          even_divisible: if True, guarantee every partition has same length.
  
      Examples::
  
          >>> data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
          >>> classes = [2, 0, 2, 1, 3, 2, 2, 0, 2, 0, 3, 3, 1, 3]
          >>> partition_dataset_classes(data, classes, shuffle=False, ratios=[2, 1])
          [[2, 8, 4, 1, 3, 6, 5, 11, 12], [10, 13, 7, 9, 14]]
  
      """
      if not issequenceiterable(classes) or len(classes) != len(data):
          raise ValueError(
              f"length of classes {classes} must match the dataset length {len(data)}."
          )
      datasets = []
      class_indices = defaultdict(list)
      for i, c in enumerate(classes):
          class_indices[c].append(i)
  
      class_partition_indices: list[Sequence] = []
      for _, per_class_indices in sorted(class_indices.items()):
          per_class_partition_indices = partition_dataset(
              data=per_class_indices,
              ratios=ratios,
              num_partitions=num_partitions,
              shuffle=shuffle,
              seed=seed,
              drop_last=drop_last,
              even_divisible=even_divisible,
          )
          if not class_partition_indices:
              class_partition_indices = per_class_partition_indices
          else:
              for part, data_indices in zip(
                  class_partition_indices, per_class_partition_indices
              ):
                  part += data_indices
  
      rs = np.random.RandomState(seed)
      for indices in class_partition_indices:
          if shuffle:
              rs.shuffle(indices)
          datasets.append([data[j] for j in indices])
  
      return datasets
  
imports: from __future__ import annotations
  import hashlib
  import json
  import logging
  import math
  import os
  import pickle
  import sys
  from collections import abc, defaultdict
  from collections.abc import Generator, Iterable, Mapping, Sequence, Sized
  from copy import deepcopy
  from functools import reduce
  from itertools import product, starmap, zip_longest
  from pathlib import PurePath
  from typing import Any
  import numpy
  import torch
  from torch.utils.data._utils.collate import default_collate
  from monai import config
  from monai.config.type_definitions import NdarrayOrTensor, NdarrayTensor, PathLike
  from monai.data.meta_obj import MetaObj
  from monai.utils import MAX_SEED, BlendMode, Method, NumpyPadMode, TraceKeys, convert_data_type, convert_to_dst_type, ensure_tuple, ensure_tuple_rep, ensure_tuple_size, fall_back_tuple, first, get_equivalent_dtype, issequenceiterable, look_up_option, optional_import, pytorch_after
label_desc: Use image node_id 29 for calling a global function with example usage: partition_dataset_classes(data, classes, ratios, num_partitions, shuffle, seed, drop_last, even_divisible) and returns: datasets