def get_example(self, batch_size):
"""Get a single example from the tfrecord file.
Args:
batch_size: Int, minibatch size.
Returns:
tf.Example protobuf parsed from tfrecord.
"""
reader = tf.TFRecordReader()
num_epochs = None if self.is_training else 1
capacity = batch_size
path_queue = tf.train.input_producer(
[self.record_path],
num_epochs=num_epochs,
shuffle=self.is_training,
capacity=capacity)
unused_key, serialized_example = reader.read(path_queue)
features = {
"note_str": tf.FixedLenFeature([], dtype=tf.string),
"pitch": tf.FixedLenFeature([1], dtype=tf.int64),
"velocity": tf.FixedLenFeature([1], dtype=tf.int64),
"audio": tf.FixedLenFeature([64000], dtype=tf.float32),
"qualities": tf.FixedLenFeature([10], dtype=tf.int64),
"instrument_source": tf.FixedLenFeature([1], dtype=tf.int64),
"instrument_family": tf.FixedLenFeature([1], dtype=tf.int64),
}
example = tf.parse_single_example(serialized_example, features)
return example
评论列表
文章目录