(dataset, hparams, is_training)
Splice together several examples into a single example.
Splice together several examples into a single example.
Splice together several examples into a single example .
def splice_examples(dataset, hparams, is_training):
  """Splice together several examples into a single example."""
  if (not is_training) or hparams.splice_n_examples == 0:
    return dataset
  else:
    dataset = dataset.padded_batch(
        hparams.splice_n_examples, padded_shapes=dataset.output_shapes)

    def _splice(features, labels):
      """Splice together a batch of examples into a single example."""
      combine = functools.partial(
          combine_tensor_batch,
          lengths=features.length,
          max_length=hparams.max_expected_train_example_len,
          batch_size=hparams.splice_n_examples)

      combined_features = FeatureTensors(
          spec=combine(features.spec),
          length=tf.reduce_sum(features.length),
          sequence_id=tf.constant(0))
      combined_labels = LabelTensors(
          labels=combine(labels.labels),
          label_weights=combine(labels.label_weights),
          onsets=combine(labels.onsets),
          offsets=combine(labels.offsets),
          velocities=combine(labels.velocities),
          note_sequence=tf.constant(0))
      return combined_features, combined_labels

    combined_dataset = dataset.map(_splice)
    return combined_dataset
def splice_examples ( dataset , hparams , is_training ) : if ( not is_training ) or hparams . splice_n_examples == 0 : return dataset else : dataset = dataset . padded_batch ( hparams . splice_n_examples , padded_shapes = dataset . output_shapes ) def _splice ( features , labels ) : """Splice together a batch of examples into a single example.""" combine = functools . partial ( combine_tensor_batch , lengths = features . length , max_length = hparams . max_expected_train_example_len , batch_size = hparams . splice_n_examples ) combined_features = FeatureTensors ( spec = combine ( features . spec ) , length = tf . reduce_sum ( features . length ) , sequence_id = tf . constant ( 0 ) ) combined_labels = LabelTensors ( labels = combine ( labels . labels ) , label_weights = combine ( labels . label_weights ) , onsets = combine ( labels . onsets ) , offsets = combine ( labels . offsets ) , velocities = combine ( labels . velocities ) , note_sequence = tf . constant ( 0 ) ) return combined_features , combined_labels combined_dataset = dataset . map ( _splice ) return combined_dataset