import tensorflow as tf
import glob
def _parse_function(example_proto):
contexts, features = tf.parse_single_sequence_example(
example_proto,
context_features={"video_id": tf.FixedLenFeature([], tf.string),
"labels": tf.VarLenFeature(tf.int64)},
sequence_features={'audio_embedding' : tf.FixedLenSequenceFeature([10], dtype=tf.string)
})
decoded_features = tf.reshape(
tf.cast(tf.decode_raw(features['audio_embedding'], tf.uint8), tf.float32), [-1, 128])
labels = (tf.cast(
tf.sparse_to_dense(contexts["labels"].values, (527,), 1,
validate_indices=False),
tf.bool))
return decoded_features, labels # and the labels?
# Get a list of files
filenames = glob.glob('/Users/jeff/documents/jeffcode/pond5/music_genre/features/audioset_v1_embeddings/bal_train/*.tfrecord')
dataset = tf.data.TFRecordDataset(filenames)
dataset.map(_parse_function)
dataset = dataset.shuffle(buffer_size=10000)
dataset = dataset.batch(64)
iterator = dataset.make_one_shot_iterator()
#iterator = dataset.make_initializable_iterator()
#next_element = iterator.get_next()
#train_op = model_and_optimizer(images, labels)
sess = tf.Session()
for _ in range(2):
while True:
try:
# How can x fit into a model now? Is it returning the features and labels?
x = sess.run(iterator.get_next())
print(x) # This prints out the byte code at least :)
except tf.errors.OutOfRangeError:
break
def prepare_serialized_examples(serialized_example, max_quantized_value=2, min_quantized_value=-2):
contexts, features = tf.parse_single_sequence_example(
serialized_example,
context_features={"video_id": tf.FixedLenFeature([], tf.string),
"labels": tf.VarLenFeature(tf.int64)},
sequence_features={'audio_embedding': tf.FixedLenSequenceFeature([], dtype=tf.string)
})
decoded_features = tf.reshape(
tf.cast(tf.decode_raw(features['audio_embedding'], tf.uint8), tf.float32),
[-1, 128])
decoded_labels = (tf.cast(contexts["labels"].values, tf.int64))
return decoded_features, decoded_labels
dataset = tf.data.TFRecordDataset(filenames)
dataset = dataset.map(prepare_serialized_examples)
dataset = dataset.shuffle(buffer_size=10000)
dataset = dataset.batch(1)
iterator = dataset.make_initializable_iterator()
feature_batch, label_batch = iterator.get_next()with tf.Session() as sess:
sess.run(iterator.initializer)try:
while True:
embeddings, labels = sess.run([feature_batch, label_batch])...
except tf.errors.OutOfRangeError:
pass
--
You received this message because you are subscribed to the Google Groups "audioset-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to audioset-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/audioset-users/cc5b6fc8-ec99-4352-a95a-002199ed9003%40googlegroups.com.
Also, please share some helpful resources about working with Google audioset corpus if possible.