def _generate_feats_and_label_batch(filename_queue, batch_size):
"""Construct a queued batch of spectral features and transcriptions.
Args:
filename_queue: queue of filenames to read data from.
batch_size: Number of utterances per batch.
Returns:
feats: mfccs. 4D tensor of [batch_size, height, width, 3] size.
labels: transcripts. List of length batch_size.
seq_lens: Sequence Lengths. List of length batch_size.
"""
# Define how to parse the example
reader = tf.TFRecordReader()
_, serialized_example = reader.read(filename_queue)
context_features = {
"seq_len": tf.FixedLenFeature([], dtype=tf.int64),
"labels": tf.VarLenFeature(dtype=tf.int64)
}
sequence_features = {
# mfcc features are 13 dimensional
"feats": tf.FixedLenSequenceFeature([13, ], dtype=tf.float32)
}
# Parse the example (returns a dictionary of tensors)
context_parsed, sequence_parsed = tf.parse_single_sequence_example(
serialized=serialized_example,
context_features=context_features,
sequence_features=sequence_features
)
# Generate a batch worth of examples after bucketing
seq_len, (feats, labels) = tf.contrib.training.bucket_by_sequence_length(
input_length=tf.cast(context_parsed['seq_len'], tf.int32),
tensors=[sequence_parsed['feats'], context_parsed['labels']],
batch_size=batch_size,
bucket_boundaries=list(range(100, 1900, 100)),
allow_smaller_final_batch=True,
num_threads=16,
dynamic_pad=True)
return feats, tf.cast(labels, tf.int32), seq_len
评论列表
文章目录