如何读取Google开源的audioset的tfrecord文件

谷歌前段时间开源的audioset可以说是音频届的imagenet了,拥有200多万的音频和500多个分类(截止2017年3月)。官方下载地址点这里。官方提供了两种数据获取方式:一种是提供音频字典信息,由自己下载相关youtube音频;另一种以1Hz采样的128维音频特征数据,tfrecord格式数据。

那么,这些tfrecord格式的数据便可按下面的方式来读取。

import numpy as np
import tensorflow as tf

sess = tf.InteractiveSession()

filename = '2a.tfrecord'
filename_queue = tf.train.string_input_producer([filename])  # 添加队列
reader = tf.TFRecordReader()
_, serialized_example = reader.read(filename_queue)
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)
})

embedding_0 = tf.decode_raw(features['audio_embedding'], tf.uint8)  # 转换格式
embedding = tf.reshape(embedding_0, [10, 128])  # 指定embedding的结构
batch = tf.train.shuffle_batch(
[embedding], batch_size=30, capacity=2000, min_after_dequeue=1000)

tf.global_variables_initializer().run()  # 初始化变量
tf.train.start_queue_runners(sess=sess)  # 启动队列

print(embedding_0.eval().shape)  # 验证embedding的shape
audio_feature = batch.eval()  # 读取数据

“如何读取Google开源的audioset的tfrecord文件”的7个回复

  1. 怎么得到AudioSet的tfrecord格式数据,官方给了一个VGGish模型,需要用它自己提取?

    1. 在这个官方页面:https://research.google.com/audioset/download.html 里有说明。

      Manually download the tar.gz file from one of (depending on region):
      storage.googleapis.com/us_audioset/youtube_corpus/v1/features/features.tar.gz
      storage.googleapis.com/eu_audioset/youtube_corpus/v1/features/features.tar.gz
      storage.googleapis.com/asia_audioset/youtube_corpus/v1/features/features.tar.gz

  2. 请问batch_size定为30有什么意义吗?最后读取的数据是(30,10,128),是不是代表着这个文件包含着300秒的片段?

  3. 您好,请问那怎么读取每个音频的labels和video_id呢?然后您这里只是读了一个batch,那我怎么知道一个tfrecord文件包含多少个音频并且总共读出来呢?

发表回复

您的电子邮箱地址不会被公开。