理解theano中的dtype

understanding dtype in theano

我是 theano 的新手,我正在尝试在我的本地机器上重现 this 代码的结果。当我 运行 代码原样时,当我 运行 theano 函数(在 [48] 中)f_trainf_test.

时出现以下错误

TypeError: ('An update must have the same type as the original shared variable (shared_var=b_y, shared_var.type=TensorType(float32, vector), update_val=Elemwise{sub,no_inplace}.0, update_val.type=TensorType(float64, vector)).', 'If the difference is related to the broadcast pattern, you can call the tensor.unbroadcast(var, axis_to_unbroadcast[, ...]) function to remove broadcastable dimensions.')

当我换行时:

b_y = numpy.zeros(shape=(10,), dtype="float32")

b_y = numpy.zeros(shape=(10,), dtype=theano.config.floatX)

那就运行没问题了。现在在我的 .theanorc 中我有 floatX = float32。我无法理解为什么会这样。

此外,如果我将所有 dtype=theano.config.floatX 更改为 dtype="float32",那么我也会得到同样的错误。

请帮助我了解这里发生了什么。

看来您的环境有点混乱。如果不深入了解您的环境细节,我无法为您提供更好的解决方案;但每当遇到此类问题时,我总是会使用该代码环境的命令行标志。当你在命令行上 运行 代码时,你可以为 Theano 设置标志,如下所示:

THEANO_FLAGS='floatX=float32,device=gpu0'  python <myscript>.py

更多信息:http://deeplearning.net/software/theano/library/config.html

希望对您有所帮助。