python - tf.contrib.signal.stft 返回一个空矩阵

标签 python docker tensorflow ffmpeg jupyter-notebook

这是我运行的一段代码:

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())是:
[]

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

最佳答案

看来tf.contrib.ffmpeg.decode_audio返回一个形状为 (?, 1) 的张量这是 ? 的一个信号 sample 。

然而tf.contrib.signal.stft预计 (signal_count, samples)张量作为输入,因此必须事先对其进行转置。

像这样修改调用可以解决问题:

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

关于python - tf.contrib.signal.stft 返回一个空矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47729101/

相关文章:

tensorflow - 当我尝试在 jetson tx1 中加载卷积预训练模型时,tensorflow 中出现错误

python - 名称未在 Django 模型中定义

python - 使用 argparse 参数名称作为变量名称

python - 将字典键值与多值索引进行比较

Python保持排序数据的最有效方法

apache-spark - 将 spark-jobserver 部署到 BlueMix Spark 节点

python - 在 Keras/TensorFlow 中使用纯 numpy 指标作为指标

docker - Ansible 不允许我通过 SSH 连接

reactjs - 如何在 React 应用程序、Docker 和 WSL 中处理热重载?

python-3.x - ImportError : libcudnn. so.7:无法打开共享对象文件:没有这样的文件或目录