我已经在 GPU 上训练了 Theano 模型,现在想要将其设置为在服务器上运行(没有 GPU)。
首先,我遇到了由于缺少 CudaNdarray
类型而无法取消模型的问题。然后,按照this post的建议,我将选项 config.experimental.unpickle_gpu_on_cpu
设置为 True
。
但是后来我得到了这个错误:
>>> import cPickle
>>> f = open('results/model.save')
>>> cPickle.load(f)
/home/ubuntu/anaconda/lib/python2.7/site-packages/theano/sandbox/cuda/type.py:541: UserWarning: config.experimental.unpickle_gpu_on_cpu is set to True. Unpickling CudaNdarray as numpy.ndarray
warnings.warn("config.experimental.unpickle_gpu_on_cpu is set to True. Unpickling CudaNdarray as numpy.ndarray")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ubuntu/anaconda/lib/python2.7/site-packages/theano/sandbox/cuda/opt.py", line 2192, in <module>
import theano.sandbox.cuda.extra_ops
File "/home/ubuntu/anaconda/lib/python2.7/site-packages/theano/sandbox/cuda/extra_ops.py", line 424, in <module>
@register_gpu_opt()
NameError: name 'register_gpu_opt' is not defined
model.save
文件是通过以下方式生成的:
import cPickle
f = file('results/model.save', 'wb')
model_soft_predict = theano.function([x], layer3.p_y_given_x)
cPickle.dump(model_soft_predict, f, protocol=cPickle.HIGHEST_PROTOCOL)
f.close()
最佳答案
是的,这是一个典型的问题。 为什么会发生这种情况?由于theano将模型编译为c/cuda c代码,因此当模型发现编译器不一致的代码时会出现错误。
出现问题如何处理?我会选择将所有参数保存为 numpy 值。例如
values_to_pickle = [p.get_value() for p in model.all_parameters()]
关于python - Theano - 名称错误 : name 'register_gpu_opt' is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32082696/