code: def example_protos_from_path(
      path,
      num_examples=10,
      start_index=0,
      parse_examples=True,
      sampling_odds=1,
      example_class=tf.train.Example,
  ):
      """Returns a number of examples from the provided path.
  
      Args:
        path: A string path to the examples.
        num_examples: The maximum number of examples to return from the path.
        parse_examples: If true then parses the serialized proto from the path into
            proto objects. Defaults to True.
        sampling_odds: Odds of loading an example, used for sampling. When >= 1
            (the default), then all examples are loaded.
        example_class: tf.train.Example or tf.train.SequenceExample class to load.
            Defaults to tf.train.Example.
  
      Returns:
        A list of Example protos or serialized proto strings at the path.
  
      Raises:
        InvalidUserInputError: If examples cannot be procured from the path.
      """
  
      def append_examples_from_iterable(iterable, examples):
          for value in iterable:
              if sampling_odds >= 1 or random.random() < sampling_odds:
                  examples.append(
                      example_class.FromString(value)
                      if parse_examples
                      else value
                  )
                  if len(examples) >= num_examples:
                      return
  
      examples = []
  
      if path.endswith(".csv"):
  
          def are_floats(values):
              for value in values:
                  try:
                      float(value)
                  except ValueError:
                      return False
              return True
  
          csv.register_dialect("CsvDialect", skipinitialspace=True)
          rows = csv.DictReader(open(path), dialect="CsvDialect")
          for row in rows:
              if sampling_odds < 1 and random.random() > sampling_odds:
                  continue
              example = tf.train.Example()
              for col in row.keys():
                  # Parse out individual values from vertical-bar-delimited lists
                  values = [val.strip() for val in row[col].split("|")]
                  if are_floats(values):
                      example.features.feature[
                          col
                      ].float_list.value.extend(
                          [float(val) for val in values]
                      )
                  else:
                      example.features.feature[
                          col
                      ].bytes_list.value.extend(
                          [val.encode("utf-8") for val in values]
                      )
              examples.append(
                  example
                  if parse_examples
                  else example.SerializeToString()
              )
              if len(examples) >= num_examples:
                  break
          return examples
  
      filenames = filepath_to_filepath_list(path)
      compression_types = [
          "",  # no compression (distinct from `None`!)
          "GZIP",
          "ZLIB",
      ]
      current_compression_idx = 0
      current_file_index = 0
      while current_file_index < len(
          filenames
      ) and current_compression_idx < len(compression_types):
          try:
              record_iterator = (
                  tf.compat.v1.python_io.tf_record_iterator(
                      path=filenames[current_file_index],
                      options=tf.io.TFRecordOptions(
                          compression_types[current_compression_idx]
                      ),
                  )
              )
              append_examples_from_iterable(record_iterator, examples)
              current_file_index += 1
              if len(examples) >= num_examples:
                  break
          except tf.errors.DataLossError:
              current_compression_idx += 1
          except (IOError, tf.errors.NotFoundError) as e:
              raise common_utils.InvalidUserInputError(e)
  
      if examples:
          return examples
      else:
          raise common_utils.InvalidUserInputError(
              "No examples found at "
              + path
              + ". Valid formats are TFRecord files."
          )
  
file_path: what-if-tool/utils/platform_utils.py
imports: import csv
  from glob import glob
  from grpc.beta import implementations
  import os
  import random
  from six.moves.urllib.parse import urlparse
  import tensorflow
  from utils import common_utils
  from tensorflow.core.framework import types_pb2
  from tensorflow_serving.apis import classification_pb2
  from tensorflow_serving.apis import predict_pb2
  from tensorflow_serving.apis import prediction_service_pb2
  from tensorflow_serving.apis import regression_pb2
label_desc: Use image node_id 4 for calling a global function with example usage: example_protos_from_path(path, num_examples, start_index, parse_examples, sampling_odds, example_class) and returns: examples, examples, True, False