我正在使用内插模块中的LinearNDInterpolator,并且在某个地方失去了记忆。如果有人能告诉我怎么找回它,那就太好了。我正在执行如下操作(在这里我跟踪了内存的使用情况):
import numpy as np
from scipy import interpolate as irp # mem: 14.7 MB
X = np.random.random_sample( (2**18,2) ) # mem: 18.7 MB
Y = np.random.random_sample( (2**18,1) ) # mem: 20.7 MB
f = irp.LinearNDInterpolator( X, Y ) # mem: 85.9 MB
del f # mem: 57.9 MB我正在做的插值要小得多,但是很多次都会导致最终的崩溃。有人能说出这个额外的内存挂在哪里,我如何恢复它吗?
编辑1:
轮廓仪输出
Line # Mem usage Increment Line Contents
================================================
4 15.684 MiB 0.000 MiB @profile
5 def wrapper():
6 19.684 MiB 4.000 MiB X = np.random.random_sample( (2**18,2) )
7 21.684 MiB 2.000 MiB Y = np.random.random_sample( (2**18,1) )
8 86.699 MiB 65.016 MiB f = irp.LinearNDInterpolator( X, Y )
9 58.703 MiB -27.996 MiB del f编辑2:
我正在运行的实际代码如下。每个xtr为(2*w^2,w^2) uint8。它的工作,直到我到w=61,但只有当我分别运行每w(所以r_21 .r_51和运行每个)。奇怪的是,每个不足61岁的人仍然占据着所有的记忆,但直到61年才触底。
from numpy import *
from scipy import interpolate as irp
for w in r_[ 21:72:10 ]:
print w
t = linspace(-1,1,w)
xx,yy = meshgrid(t,t)
xx,yy = xx.flatten(), yy.flatten()
P = c_[sign(xx)*abs(xx)**0.65, sign(yy)*abs(yy)**0.65]
del t
x = load('../../windows/%d/raw/xtr.npy'%w)
xo = zeros(x.shape,dtype=uint8)
for i in range(x.shape[0]):
f = irp.LinearNDInterpolator( P, x[i,:] )
out = f( xx, yy )
xo[i,:] = out
del f, out
save('../../windows/%d/lens/xtr.npy'%w,xo)
del x, xo此消息在61上出错:
Python(10783) malloc: *** mmap(size=16777216) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
Traceback (most recent call last):
File "make_lens.py", line 16, in <module>
f = irp.LinearNDInterpolator( P, x[i,:] )
File "interpnd.pyx", line 204, in scipy.interpolate.interpnd.LinearNDInterpolator.__init__ (scipy/interpolate/interpnd.c:3794)
File "qhull.pyx", line 1703, in scipy.spatial.qhull.Delaunay.__init__ (scipy/spatial/qhull.c:13267)
File "qhull.pyx", line 1432, in scipy.spatial.qhull._QhullUser.__init__ (scipy/spatial/qhull.c:11989)
File "qhull.pyx", line 1712, in scipy.spatial.qhull.Delaunay._update (scipy/spatial/qhull.c:13470)
File "qhull.pyx", line 526, in scipy.spatial.qhull._Qhull.get_simplex_facet_array (scipy/spatial/qhull.c:5453)
File "qhull.pyx", line 594, in scipy.spatial.qhull._Qhull._get_simplex_facet_array (scipy/spatial/qhull.c:6010)
MemoryError编辑3:
指向与上述代码相同但独立于我的数据的代码的链接:
我收到与上面相同的错误。我在一个英特尔核心2双macbook与2GB的RAM。读x和写xo只合并到~53 is,但是随着循环的进行,内存的使用量远远超出了所需的范围。
发布于 2014-03-20 20:24:24
这个问题在我没有使用的SciPy的后期版本中得到了修正:
https://stackoverflow.com/questions/22492230
复制相似问题