code: def read_examples(
      examples,
      is_training,
      shuffle_examples,
      skip_n_initial_records,
      hparams,
  ):
      """Returns a tf.data.Dataset from TFRecord files.
  
      Args:
        examples: A string path to a TFRecord file of examples, a python list of
          serialized examples, or a Tensor placeholder for serialized examples.
        is_training: Whether this is a training run.
        shuffle_examples: Whether examples should be shuffled.
        skip_n_initial_records: Skip this many records at first.
        hparams: HParams object specifying hyperparameters.
  
      Returns:
        A tf.data.Dataset.
      """
      if is_training and not shuffle_examples:
          raise ValueError(
              "shuffle_examples must be True if is_training is True"
          )
  
      if isinstance(examples, str):
          # Read examples from a TFRecord file containing serialized NoteSequence
          # and audio.
          sharded_filenames = generate_sharded_filenames(examples)
          if len(sharded_filenames) == 1:
              # Could be a glob pattern.
              filenames = tf.data.Dataset.list_files(
                  generate_sharded_filenames(examples),
                  shuffle=shuffle_examples,
              )
          else:
              # If we've already expanded the list of sharded filenames, don't send to
              # Dataset.list_files because that will attempt to execute a potentially
              # slow (especially for network filesystems) glob expansion on each entry
              # in the already expanded list.
              if shuffle_examples:
                  np.random.shuffle(sharded_filenames)
              filenames = tf.data.Dataset.from_tensor_slices(
                  sharded_filenames
              )
  
          if shuffle_examples:
              input_dataset = filenames.apply(
                  tf.data.experimental.parallel_interleave(
                      tf.data.TFRecordDataset,
                      sloppy=True,
                      cycle_length=8,
                  )
              )
          else:
              input_dataset = tf.data.TFRecordDataset(filenames)
      else:
          input_dataset = tf.data.Dataset.from_tensor_slices(examples)
  
      if shuffle_examples:
          input_dataset = input_dataset.shuffle(
              hparams.shuffle_buffer_size
          )
      if is_training:
          input_dataset = input_dataset.repeat()
      if skip_n_initial_records:
          input_dataset = input_dataset.skip(skip_n_initial_records)
  
      return input_dataset
  
imports: import collections
  import functools
  import io
  import re
  import wave
  import zlib
  import librosa
  from magenta.models.onsets_frames_transcription import audio_transform
  from magenta.models.onsets_frames_transcription import constants
  from magenta.models.onsets_frames_transcription import drum_mappings
  from magenta.models.onsets_frames_transcription import melspec_input
  from note_seq import audio_io
  from note_seq import sequences_lib
  from note_seq.protobuf import music_pb2
  import numpy
  import tensorflow.compat.v1
label_desc: Use image node_id 24 for calling a global function with example usage: read_examples(examples, is_training, shuffle_examples, skip_n_initial_records, hparams) and returns: input_dataset