谷歌前段时间开源的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() # 读取数据
怎么得到AudioSet的tfrecord格式数据,官方给了一个VGGish模型,需要用它自己提取?
在这个官方页面: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
请问,这样读取的效率怎么样,比直接读文件会快吗?
肯定要快,毕竟少了图片文件的解码过程,况且tfrecord还是tensorflow的专用格式
请问batch_size定为30有什么意义吗?最后读取的数据是(30,10,128),是不是代表着这个文件包含着300秒的片段?
batch_size指从队列中提取新的批量大小,30这里没啥特殊意义。不能理解为300秒
您好,请问那怎么读取每个音频的labels和video_id呢?然后您这里只是读了一个batch,那我怎么知道一个tfrecord文件包含多少个音频并且总共读出来呢?