python - 如何从 Google 的 AudioSet 中提取音频嵌入(特征)?

标签 python tensorflow protocol-buffers

我说的是 https://research.google.com/audioset/download.html 上提供的音频特征数据集作为由帧级音频 tfrecord 组成的 tar.gz 存档。

从 tfrecord 文件中提取其他所有内容都可以正常工作(我可以提取键:video_id、start_time_seconds、end_time_seconds、标签),但训练所需的实际嵌入似乎根本不存在。当我迭代数据集中任何 tfrecord 文件的内容时,仅打印四个键 video_id、start_time_seconds、end_time_seconds 和 labels。

这是我正在使用的代码:

import tensorflow as tf
import numpy as np

def readTfRecordSamples(tfrecords_filename):

    record_iterator = tf.python_io.tf_record_iterator(path=tfrecords_filename)

    for string_record in record_iterator:
        example = tf.train.Example()
        example.ParseFromString(string_record)
        print(example)  # this prints the abovementioned 4 keys but NOT audio_embeddings

        # the first label can be then parsed like this:
        label = (example.features.feature['labels'].int64_list.value[0])
        print('label 1: ' + str(label))

        # this, however, does not work:
        #audio_embedding = (example.features.feature['audio_embedding'].bytes_list.value[0])

readTfRecordSamples('embeddings/01.tfrecord')

提取 128 维嵌入有什么技巧吗? 或者它们真的不在这个数据集中吗?

最佳答案

解决了,tfrecord 文件需要作为序列示例而不是示例来读取。如果行以上代码有效

example = tf.train.Example()

被替换为

example = tf.train.SequenceExample()

只需运行即可查看嵌入和所有其他内容

print(example)

关于python - 如何从 Google 的 AudioSet 中提取音频嵌入(特征)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46204992/

相关文章:

javascript - Sails.js socket.io protobuf.js 编码消息导致错误 : "Illegal buffer" on decode in browser

dart - 无法使原始路径相对并且没有这样的文件或目录

python - 如何设置 x 标签以在 Bokeh 图中显示日期时间?

发布但不返回任何值的 jQuery Python,Flask

python - 大收件箱 : Too many arguments for command 上的 imaplib.select

python - 如何获得两个以上类别的预测标签?

Python GUI 多处理并且仍然卡住

python - 一张一张保存GAN生成的图像

python - 基本镜像满足tensorflow版本,但docker仍然从requirements.txt下载tensorflow

python - 如何获取 protobuf 消息中定义的变量类型?