code: def common_paths_root(
      exp_list: Sequence[FilesDefT],
  ) -> Tuple[Union[str, None], Sequence[FilesDefT]]:
      common_root = None
  
      # Detect common root
      try:
          all_paths = [pattern_tuple[0] for pattern_tuple in exp_list]
  
          common_root = os.path.commonpath(all_paths)
      except ValueError:
          # commonpath may throw a ValueError in different situations!
          # See the official documentation for more details
          pass
  
      if (
          common_root is not None
          and len(common_root) > 0
          and common_root != "/"
      ):
          has_common_root = True
          common_root = str(common_root)
      else:
          has_common_root = False
          common_root = None
  
      exp_list_result: Sequence[FilesDefT]
  
      if has_common_root:
          # print(f'Common root found: {common_root}!')
          # All paths have a common filesystem root
          # Remove it from all paths!
          single_path_case = False
          exp_tuples: List[FilesDefT] = list()
  
          for x in exp_list:
              if single_path_case:
                  break
  
              rel = os.path.relpath(x[0], common_root)
              if len(rel) == 0 or rel == ".":
                  # May happen if the dataset has a single path
                  single_path_case = True
                  break
              exp_tuples.append((rel, *x[1:]))  # type: ignore
  
          if not single_path_case:
              exp_list_result = exp_tuples
          else:
              exp_list_result = exp_list
              common_root = None
      else:
          exp_list_result = exp_list
  
      return common_root, exp_list_result
  
imports: from pathlib import Path
  from typing import Callable, Generic, List, Tuple, Sequence, Optional, TypeVar, Union
  import torch.utils.data
  from PIL import Image
  import os
  import os.path
  from torch import Tensor
  from torchvision.transforms.functional import crop
  from .transform_groups import XTransform, YTransform
label_desc: Use image node_id 5 for calling a global function with example usage: common_paths_root(exp_list) and returns: common_root,  exp_list_result