docstr: Tests for correctness of batches.
docstr_tok: ["Tests","for","correctness","of","batches","."]
code: def _ValidateProvideBatch(
      self,
      examples,
      truncated_length,
      batch_size,
      expected_inputs,
      feed_dict=None,
  ):
      """Tests for correctness of batches."""
      hparams = copy.deepcopy(configs.DEFAULT_HPARAMS)
      hparams.batch_size = batch_size
      hparams.truncated_length_secs = (
          truncated_length / data.hparams_frames_per_second(hparams)
      )
  
      with self.test_session() as sess:
          dataset = data.provide_batch(
              examples=examples,
              preprocess_examples=True,
              params=hparams,
              is_training=False,
              shuffle_examples=False,
              skip_n_initial_records=0,
          )
          iterator = tf.data.make_initializable_iterator(dataset)
          next_record = iterator.get_next()
          sess.run(
              [
                  tf.initializers.local_variables(),
                  tf.initializers.global_variables(),
                  iterator.initializer,
              ],
              feed_dict=feed_dict,
          )
          for i in range(0, len(expected_inputs), batch_size):
              # Wait to ensure example is pre-processed.
              time.sleep(0.1)
              features, labels = sess.run(next_record)
              inputs = [
                  features.spec,
                  labels.labels,
                  features.length,
                  features.sequence_id,
              ]
              max_length = np.max(inputs[2])
              for j in range(batch_size):
                  # Add batch padding if needed.
                  input_length = expected_inputs[i + j][2]
                  if input_length < max_length:
                      expected_inputs[i + j] = list(
                          expected_inputs[i + j]
                      )
                      pad_amt = max_length - input_length
                      expected_inputs[i + j][0] = np.pad(
                          expected_inputs[i + j][0],
                          [(0, pad_amt), (0, 0)],
                          "constant",
                      )
                      expected_inputs[i + j][1] = np.pad(
                          expected_inputs[i + j][1],
                          [(0, pad_amt), (0, 0)],
                          "constant",
                      )
                  for exp_input, input_ in zip(
                      expected_inputs[i + j], inputs
                  ):
                      self.assertAllEqual(
                          np.squeeze(exp_input), np.squeeze(input_[j])
                      )
  
          with self.assertRaisesOpError("End of sequence"):
              _ = sess.run(next_record)
  
imports: import copy
  import tempfile
  import time
  from magenta.models.onsets_frames_transcription import configs
  from magenta.models.onsets_frames_transcription import constants
  from magenta.models.onsets_frames_transcription import data
  from note_seq import audio_io
  from note_seq import sequences_lib
  from note_seq import testing_lib
  from note_seq.protobuf import music_pb2
  import numpy
  import tensorflow.compat.v1
label_desc: Use image node_id 4 for calling the DataTest obj's underlying member method code with example usage: obj._ValidateProvideBatch(examples, truncated_length, batch_size, expected_inputs, feed_dict) without return types