code: def _convert_dataset_to_list(
      dataset,
      dataset_type_spec,
      data_size_warning_flag=True,
      ensure_shape_similarity=True,
  ):
      """Convert `dataset` object to a list of samples.
  
      Args:
          dataset: A `tf.data.Dataset`, a `torch.utils.data.Dataset` object,
              or a list/tuple of arrays.
          dataset_type_spec: the type of the dataset.
          data_size_warning_flag: If set to `True`, a warning will
              be issued if the dataset takes longer than 10 seconds to iterate.
              Defaults to `True`.
          ensure_shape_similarity: If set to `True`, the shape of
              the first sample will be used to validate the shape of rest of the
              samples. Defaults to `True`.
  
      Returns:
          List: A list of samples.
      """
      dataset_iterator = _get_data_iterator_from_dataset(
          dataset, dataset_type_spec
      )
      dataset_as_list = []
  
      start_time = time.time()
      for sample in _get_next_sample(
          dataset_iterator,
          ensure_shape_similarity,
          data_size_warning_flag,
          start_time,
      ):
          if dataset_type_spec in [tuple, list]:
              # The try-except here is for NumPy 1.24 compatibility, see:
              # https://numpy.org/neps/nep-0034-infer-dtype-is-object.html
              try:
                  arr = np.array(sample)
              except ValueError:
                  arr = np.array(sample, dtype=object)
              dataset_as_list.append(arr)
          else:
              dataset_as_list.append(sample)
  
      return dataset_as_list
  
imports: import os
  import random
  import time
  import warnings
  from multiprocessing.pool import ThreadPool
  import numpy
  from keras.api_export import keras_export
  from keras.utils import io_utils
  from keras.utils.module_utils import tensorflow
label_desc: Use image node_id 2 for calling a global function with example usage: _convert_dataset_to_list(dataset, dataset_type_spec, data_size_warning_flag, ensure_shape_similarity) and returns: dataset_as_list