【问题标题】:AudioSet and Tensorflow UnderstandingAudioSet 和 TensorFlow 的理解
【发布时间】:2017-03-09 19:27:14
【问题描述】:

AudioSet 发布并为那些为研究进行可靠分析的人提供了一个全新的研究领域,最近几天我一直在努力深入挖掘如何分析和解码这些数据。

数据在 .tfrecord 文件中给出,这是一个小的 sn-p。

�^E^@^@^@^@^@^@C�bd
u
^[
^Hvideo_id^R^O

^KZZcwENgmOL0
^^
^Rstart_time_seconds^R^H^R^F
^D^@^@�C
^X
^Flabels^R^N^Z^L

�^B�^B�^B�^B�^B
^\
^Pend_time_seconds^R^H^R^F
^D^@^@�C^R�

�

^Oaudio_embedding^R�

�^A
�^A
�^A3�^] q^@�Z�r�����w���Q����.���^@�b�{m�^@P^@^S����,^]�x�����:^@����^@^@^Z0��^@]^Gr?v(^@^U^@��^EZ6�$
�^A

给出的示例原型是:

context: {
  feature: {
    key  : "video_id"
    value: {
      bytes_list: {
        value: [YouTube video id string]
      }
    }
  }
  feature: {
    key  : "start_time_seconds"
    value: {
      float_list: {
        value: 6.0
      }
    }
  }
  feature: {
    key  : "end_time_seconds"
    value: {
      float_list: {
        value: 16.0
      }
    }
  }
  feature: {
    key  : "labels"
      value: {
        int64_list: {
          value: [1, 522, 11, 172] # The meaning of the labels can be found here.
        }
      }
    }
}
feature_lists: {
  feature_list: {
    key  : "audio_embedding"
    value: {
      feature: {
        bytes_list: {
          value: [128 8bit quantized features]
        }
      }
      feature: {
        bytes_list: {
          value: [128 8bit quantized features]
        }
      }
    }
    ... # Repeated for every second of the segment
  }

}

我在这里非常直接的问题 - 我似乎无法找到好的信息是 - 我如何在两者之间干净地转换?

如果我有一个机器可读的文件,如何使它成为人类可读的,以及其他方式。

我找到了this,它获取图片的 tfrecord 并将其转换为可读格式...但我似乎无法将其转换为与 AudioSet 一起使用的形式

【问题讨论】:

    标签: python-2.7 tensorflow


    【解决方案1】:

    这对我有用,将功能存储在 feat_audio 中。绘制它们,将它们转换为 ndarray 并相应地重塑它们。

    audio_record = '/audioset_v1_embeddings/eval/_1.tfrecord'
    vid_ids = []
    labels = []
    start_time_seconds = [] # in secondes
    end_time_seconds = []
    feat_audio = []
    count = 0
    for example in tf.python_io.tf_record_iterator(audio_record):
        tf_example = tf.train.Example.FromString(example)
        #print(tf_example)
        vid_ids.append(tf_example.features.feature['video_id'].bytes_list.value[0].decode(encoding='UTF-8'))
        labels.append(tf_example.features.feature['labels'].int64_list.value)
        start_time_seconds.append(tf_example.features.feature['start_time_seconds'].float_list.value)
        end_time_seconds.append(tf_example.features.feature['end_time_seconds'].float_list.value)
    
        tf_seq_example = tf.train.SequenceExample.FromString(example)
        n_frames = len(tf_seq_example.feature_lists.feature_list['audio_embedding'].feature)
    
        sess = tf.InteractiveSession()
        rgb_frame = []
        audio_frame = []
        # iterate through frames
        for i in range(n_frames):
            audio_frame.append(tf.cast(tf.decode_raw(
                    tf_seq_example.feature_lists.feature_list['audio_embedding'].feature[i].bytes_list.value[0],tf.uint8)
                           ,tf.float32).eval())
    
        sess.close()
        feat_audio.append([])
    
        feat_audio[count].append(audio_frame)
        count+=1
    

    【讨论】:

      【解决方案2】:

      这是我到目前为止所做的。 prepare_serialized_examples 来自 youtube-8m starter code。 我希望这会有所帮助:)

      import tensorflow as tf
      
      feature_names = 'audio_embedding'
      
      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([10], dtype=tf.string)
          })
      
          decoded_features = tf.reshape(
          tf.cast(tf.decode_raw(features['audio_embedding'], tf.uint8), tf.float32),
          [-1, 128])
      
          return contexts, decoded_features
      
      
      filename = '/audioset_v1_embeddings/bal_train/2a.tfrecord'
      filename_queue = tf.train.string_input_producer([filename], num_epochs=1)
      
      reader = tf.TFRecordReader()
      
      with tf.Session() as sess:
          
          _, serialized_example = reader.read(filename_queue)
          context, features = prepare_serialized_examples_(serialized_example)
      
          init_op = tf.initialize_all_variables()
          sess.run(init_op)
      
          coord = tf.train.Coordinator()
          threads = tf.train.start_queue_runners(coord=coord)
      
          print(sess.run(features))
      
          coord.request_stop()
          coord.join(threads)
      

      【讨论】:

      • 好的。所以我们有上下文和特征..这些对象的类型是什么?如何以人类可读的方式打印它们?
      • @Zach 花费的时间比预期的要长。对于那个很抱歉。我已经更新了我的答案。 prepare_serialized_examples_ 内部的解码用于读取浮点数而不是二进制值。您可能已经知道您的图表应该在会话中运行才能被计算。
      • @jerpint 粘贴时丢失了一些东西。我已经更新了我的代码。
      【解决方案3】:

      AudioSet 数据不是 tensorflow.Example protobuf,就像您链接的图像示例一样。这是一个SequenceExample

      我还没有测试过,但是如果您将 tf.parse_single_example 替换为 tf.parse_single_sequence_example(并替换字段名称),您应该能够使用您链接的代码。

      【讨论】:

      • 谢谢 - 这让我走得很远,但是现在 'features' 返回一个指针,并尝试打印它给出: TypeError: Expected binary or unicode string, got {'labels': , 'start_time_seconds': , 'video_id': , 'end_time_seconds': }
      • 这将返回一个张量字典。您现在可以在计算图中使用它们,例如one_video_id = sess.run(features['video_id'])。或者使用tf.train.shuffle_batch 开始批量处理它们。有关图形执行的更多详细信息:tensorflow.org/programmers_guide/…
      【解决方案4】:

      YouTube-8Mstarter code 应该可以与 AudioSet tfrecord 文件一起使用。

      【讨论】:

      • 当然——我已经启动并运行了......问题是我需要自己独立验证和运行数据。这包括可视化和观察实际数据。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-03
      • 1970-01-01
      相关资源
      最近更新 更多