code: def leaf_datasets(
      dataset: TraverseT, include_leaf_transforms: bool = True
  ):
      """
      Obtains the leaf datasets of a Dataset.
  
      This is a low level utility. For most use cases, it is better to use
      :func:`single_flat_dataset` or :func:`flat_datasets_from_benchmark`.
  
      :param dataset: The dataset to traverse.
      :param include_leaf_transforms: If True, include the transformations
          found in the leaf dataset in the transforms list. Defaults to True.
      :return: A dictionary mapping each leaf dataset to a list of tuples.
          Each tuple contains two elements: the index and the transformation
          applied to that exemplar.
      """
  
      def leaf_selector(subset, indices, transforms):
          if isinstance(
              subset,
              (AvalancheDataset, FlatData, Subset, ConcatDataset),
          ):
              # Returning None => continue traversing
              return None
  
          if indices is None:
              indices = range(len(subset))
  
          if include_leaf_transforms:
              leaf_transforms = (
                  _extract_transforms_from_standard_dataset(subset)
              )
  
              if leaf_transforms is not None:
                  transforms = list(transforms) + [leaf_transforms]
  
          return [(subset, idx, transforms) for idx in indices]
  
      def transform_selector(subset, transforms):
          if isinstance(subset, _FlatDataWithTransform):
              if (
                  subset._frozen_transform_groups is not None
                  and not isinstance(
                      subset._frozen_transform_groups,
                      EmptyTransformGroups,
                  )
              ):
                  transforms = list(transforms) + [
                      subset._frozen_transform_groups[
                          subset._frozen_transform_groups.current_group
                      ]
                  ]
              if (
                  subset._transform_groups is not None
                  and not isinstance(
                      subset._transform_groups, EmptyTransformGroups
                  )
              ):
                  transforms = list(transforms) + [
                      subset._transform_groups[
                          subset._transform_groups.current_group
                      ]
                  ]
  
          return transforms
  
      leaves = _traverse_supported_dataset_with_intermediate(
          dataset,
          leaf_selector,
          intermediate_selector=transform_selector,
          intermediate=[],
      )
  
      leaves_dict: Dict[Any, List[Tuple[int, Any]]] = defaultdict(list)
      for leaf_dataset, idx, transform in leaves:
          transform_reversed = list(reversed(transform))
          leaves_dict[leaf_dataset].append((idx, transform_reversed))
  
      return leaves_dict
  
file_path: avalanche/avalanche/benchmarks/utils/dataset_traversal_utils.py
imports: from collections import OrderedDict, defaultdict, deque
  from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, TypeVar, Union
  from avalanche.benchmarks.scenarios.generic_scenario import CLScenario
  from avalanche.benchmarks.utils.data import _FlatDataWithTransform, AvalancheDataset
  from avalanche.benchmarks.utils.dataset_definitions import IDataset
  from avalanche.benchmarks.utils.dataset_utils import find_list_from_index
  from avalanche.benchmarks.utils.flat_data import FlatData
  from torch.utils.data import Subset, ConcatDataset, Dataset
  from avalanche.benchmarks.utils.transform_groups import EmptyTransformGroups
  from avalanche.benchmarks.utils.transforms import TupleTransform
  from torchvision.datasets.vision import StandardTransform
label_desc: Use image node_id 5 for calling a global function with example usage: leaf_datasets(dataset, include_leaf_transforms) and returns: leaves_dict, unknown, transforms, None