最近在做科研过程中,用到了theano符号计算框架,我在原有程序的基础上做了改动,但程序一直报错,而theano程序又比较难调试,甚是纠结,在反复测试了好久后才弄明白,故在这里把它们记录下来,以免自己以后可能陷入同一个“坑”。
(1)错误提示“UnboundLocalError: local variable ‘e0’ referenced before assignment”;
错误样例:
import theano
from theano import tensor as T
sample = theano.tensor.vector()
W = theano.shared([[1,2,3], [4,5,6]])
values = theano.dot(sample, W)
gibbs10 = theano.function([sample], values)
print(gibbs10([1,1]))
解决办法:theano.shared()函数的value属性接收numpy.array类型的初始化数据,可先把列表数据强制转换成np.array类型。
(2)错误提示“AsTensorError: (‘Variable type field must be a TensorType.’, , <theano.gof.type.Generic object at 0x7f1184084860>)”;
错误样例:
import theano
from theano import tensor as T
sample = theano.tensor.vector()
W = theano.shared([[1,2,3], [4,5,6]])
values = T.dot(sample, W)
gibbs10 = theano.function([sample], values)
print(gibbs10([1,1]))
解决办法:同(1)。
(3)错误提示“CUDA driver version is insufficient for CUDA runtime version”;
错误原因:显卡驱动版本太低,不能满足CUDA运行库的版本要求;