【问题标题】:tf.contrib.signal.stft returns an empty matrixtf.contrib.signal.stft 返回一个空矩阵
【发布时间】:2017-12-09 13:34:04
【问题描述】:

这是我运行的一段代码:

import tensorflow as tf

sess = tf.InteractiveSession()

filename = 'song.mp3' # 30 second mp3 file
SAMPLES_PER_SEC = 44100

audio_binary = tf.read_file(filename)

pcm = tf.contrib.ffmpeg.decode_audio(audio_binary, file_format='mp3', samples_per_second=SAMPLES_PER_SEC, channel_count = 1)
stft = tf.contrib.signal.stft(pcm, frame_length=1024, frame_step=512, fft_length=1024)

sess.close()

mp3 文件被正确解码,因为print(pcm.eval().shape) 返回:

(1323119, 1)

当我用print(pcm.eval()[1000:1010]) 打印它们时,甚至还有一些实际的非零值:

[[ 0.18793298]
 [ 0.16214484]
 [ 0.16022217]
 [ 0.15918455]
 [ 0.16428113]
 [ 0.19858395]
 [ 0.22861415]
 [ 0.2347789 ]
 [ 0.22684409]
 [ 0.20728172]]

但由于某种原因,print(stft.eval().shape) 的计算结果为:

(1323119, 0, 513) # why the zero dimension?

因此print(stft.eval()) 是:

[]

根据thistf.contrib.signal.stft 输出的第二个维度等于帧数。为什么没有框架?

【问题讨论】:

    标签: python docker tensorflow ffmpeg jupyter-notebook


    【解决方案1】:

    似乎tf.contrib.ffmpeg.decode_audio 返回了一个形状为(?, 1) 的张量,这是? 样本的一个信号。

    但是 tf.contrib.signal.stft 期望 (signal_count, samples) 张量作为输入,因此必须事先对其进行转置。

    像这样修改调用就可以了:

    stft = tf.contrib.signal.stft(tf.transpose(pcm), frame_length=1024, frame_step=512, fft_length=1024)
    

    【讨论】:

      猜你喜欢
      • 2018-07-31
      • 1970-01-01
      • 2021-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多