code: def compute_split_info_from_directory(
      *,
      out_dir: Optional[epath.PathLike] = None,
      data_dir: epath.PathLike,
      filename_template: Union[
          None, str, naming.ShardedFileTemplate
      ] = None,
  ) -> Sequence[split_lib.SplitInfo]:
      """Compute the split info for the splits in the given data dir.
  
      Arguments:
        out_dir: directory where to save the metadata. It should be available from
          the apache beam workers. If not set, apache beam won't be used (only
          available with some file formats).
        data_dir: directory where the data is.
        filename_template: the template to which the data files correspond. If None,
          then the default template is used.
  
      Returns:
        list of split infos for the splits in the given data dir.
      """
      data_dir = epath.Path(data_dir)
      if filename_template is None:
          filename_template = naming.ShardedFileTemplate(
              data_dir=data_dir
          )
      elif isinstance(filename_template, str):
          filename_template = naming.ShardedFileTemplate(
              template=filename_template, data_dir=data_dir
          )
      filename_template = filename_template.replace(data_dir=data_dir)
  
      if (
          filename_template.dataset_name is None
          or filename_template.filetype_suffix is None
      ):
          # Get the dataset name and filetype suffix from the files in the data dir.
          files_per_split = _extract_split_files(filename_template)
          filename_template = _enrich_filename_template(
              filename_template=filename_template,
              files_per_split=files_per_split,
          )
      return compute_split_info(
          out_dir=out_dir, filename_template=filename_template
      )
  
imports: import collections
  from collections.abc import Mapping, Sequence, Set
  import dataclasses
  import functools
  import itertools
  import os
  import pprint
  from typing import Optional, Type, Union, cast
  from etils import epath
  from tensorflow_datasets.core import file_adapters
  from tensorflow_datasets.core import lazy_imports_lib
  from tensorflow_datasets.core import naming
  from tensorflow_datasets.core import splits
  from tensorflow_datasets.core import utils
  from tensorflow_datasets.core.proto import dataset_info_pb2
  from tensorflow_datasets.core.utils.lazy_imports_utils import apache_beam
  from tensorflow_datasets.core.utils.lazy_imports_utils import array_record_data_source
  from google.protobuf import json_format
label_desc: Use image node_id 2 for calling a global function with example usage: compute_split_info_from_directory() and returns: compute_split_info