当我尝试使用shape.eval()打印共享变量的形状时,我得到一个"无法分配内存"错误。但是当我将它转换为numpy数组(从而将其转换为CPU)时,我不仅可以获得形状,还可以获得数组本身。看下面在pdb中停止的地方,数据已经加载到CPU / RAM然后我试图打印p1的形状:
(Pdb) p1
W
(Pdb) type(p1)
<class 'theano.sandbox.cuda.var.CudaNdarraySharedVariable'>
(Pdb) p1.shape.eval()
Problem occurred during compilation with the command line below:
/usr/bin/g++ -shared -g -O3 -fno-math-errno -Wno-unused-label -Wno-unused-variable -Wno-write-strings -D NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -m64 -fPIC -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/include/python2.7 -o /home/ubuntu/.theano/compiledir_Linux-3.13--generic-x86_64-with-Ubuntu-14.04-trusty-x86_64-2.7.6-64/tmpe2w2zz/990b9feb030f7691b8412ea91249349d.so /home/ubuntu/.theano/compiledir_Linux-3.13--generic-x86_64-with-Ubuntu-14.04-trusty-x86_64-2.7.6-64/tmpe2w2zz/mod.cpp -L/usr/lib -lpython2.7
ERROR (theano.gof.cmodule): [Errno 12] Cannot allocate memory
2015-08-20 12:09:19,032 theano.gof.cmodule cmodule.py:1083 ERROR [Errno 12] Cannot allocate memory
*** OSError: [Errno 12] Cannot allocate memory
(Pdb) a1 = np.asarray(p1.eval())
(Pdb) a1.shape
(21504, 2048)
(Pdb) a1
array([[ 0.03940072, -0.03306604, -0.00602638, ..., -0.00931167,
0.05510775, 0.02733043],
[snip]
...,
[-0.06175347, 0.03134078, -0.06079643, ..., -0.03223133,
0.00347659, 0.03415193]], dtype=float32)
对于p1,借用设置为True,但这应该无关紧要,因为我正在使用GPU,对吧?
内存中有足够的可用空间:
$ free -m
total used free shared buffers cached
Mem: 15039 14815 224 0 1 4112
-/+ buffers/cache: 10701 4338
Swap: 0 0 0
此错误是RAM(与GPU内存相对)错误,对吧?为什么我可以在将变量输入CPU(使用np.asarray)后打印形状,但shape.eval()会输出错误?
解决此问题的好方法(此外,可能会获得更多内存)?