问题描述
我正在使用 Librosa,但我遇到了内存问题。
我有很多音频文件,比如说一百个。 我一一处理音频文件。 每个音频文件按 1 分钟的块加载。 在我移动到下一个块之前处理每个块。 通过这种方式,我知道在给定的时间内,我的内存中的音频永远不会超过 60 秒。 这让我可以避免在整个过程中使用过多的内存。
出于某种原因,进程使用的内存会随着时间的推移而增长。
import librosa
import matplotlib.pyplot as plt
import os
import psutil
SAMPLING_RATE = 22050
N_FFT = 2048
HOP_LENGTH = 1024
def foo():
y,sr = librosa.load("clip_04.wav",sr=SAMPLING_RATE,offset=600,duration=60)
D = librosa.stft(y,n_fft=N_FFT,hop_length=HOP_LENGTH)
spec_mag = abs(D)
spec_db = librosa.amplitude_to_db(spec_mag)
return 42 # I return a constant to make sure the memory is (or should be) released
def main():
process = psutil.Process(os.getpid())
array = []
for i in range(100):
foo()
m = int(process.memory_info().RSS / 1024**2)
array.append(m)
plt.figure()
plt.plot(array)
plt.xlabel('iterations')
plt.ylabel('MB')
plt.show()
if __name__ == '__main__':
main()
这正常吗?如果是,有没有办法在每次迭代时清除 Librosa 内存?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)