Theano对CPU和GPU的不同结果

Huo

我有以下代码:

import theano
import theano.tensor as T
import numpy as np

x = theano.shared(np.asarray([1, 2, 3], dtype=theano.config.floatX), borrow=True)
y = T.cast(x, 'int32')
print 'type of y: ', type(y)
print 'type of y.owner.inputs[0]: ', type(y.owner.inputs[0])
print 'value of y: ', y.owner.inputs[0].get_value(borrow=True)

与CPU一起运行

$ THEANO_FLAGS=mode=FAST_RUN,device=cpu,floatX=float32 python test_share.py
type of y:  <class 'theano.tensor.var.TensorVariable'>
type of y.owner.inputs[0]:  <class 'theano.tensor.sharedvar.TensorSharedVariable'>
value of y:  [ 1.  2.  3.]

与GPU一起运行

$ THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 python test_share.py
Using gpu device 0: GeForce 310M
type of y:  <class 'theano.tensor.var.TensorVariable'>
type of y.owner.inputs[0]:  <class 'theano.tensor.var.TensorVariable'>
value of y:
Traceback (most recent call last):
  File "test_share.py", line 10, in <module>
    print 'value of y: ', y.owner.inputs[0].get_value(borrow=True)
AttributeError: 'TensorVariable' object has no attribute 'get_value'

如何获得与CPU相同的结果?

丹尼尔·伦肖

通常,用于访问计算图中的子节点的方法.owner.inputs[0]不适用于跨平台代码。

您调用共享变量,x以便访问x的正确方法是使用x.get_value()

此代码应在CPU和GPU上相同地运行:

import theano
import theano.tensor as T
import numpy as np

x = theano.shared(np.asarray([1, 2, 3], dtype=theano.config.floatX), borrow=True)
y = T.cast(x, 'int32')
print 'type of y: ', type(y)
print 'type of x: ', type(x)
print 'value of x: ', x.get_value(borrow=True)

如果要查看将符号转换操作应用于x的结果(调用的符号结果)y,则可以执行以下操作:

print 'value of y: ', y.eval()

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

为什么cpu和gpu的结果不同?

来自分类Dev

CPU和GPU生成的结果不匹配

来自分类Dev

Theano:与CPU和GPU一起获取矩阵点时的差异与数字

来自分类Dev

CUDA:cpu和gpu之间的不同答案减少

来自分类Dev

CPU和GPU的差异

来自分类Dev

CPU使用率:top和mpstat显示不同的结果

来自分类Dev

yourkit cpu view 和 top 命令 - 显示不同的结果

来自分类Dev

在CPU上执行的数学运算在GPU上有不同的结果

来自分类Dev

如何解释 GPU 和 CPU 串行版本的均值滤波器的这些结果?

来自分类Dev

CPU SIMD和GPU SIMD?

来自分类Dev

GPU和CPU之间的区别

来自分类Dev

异步CPU读取和GPU + CPU计算

来自分类Dev

XCode预编译的OpenCL在不同的Mac OS版本和交替的CPU / GPU上崩溃

来自分类Dev

XCode预编译的OpenCL在不同的Mac OS版本和交替的CPU / GPU上崩溃

来自分类Dev

> 和 &> 产生不同的结果

来自分类Dev

当东西在GPU上时评估和修改theano张量

来自分类Dev

当东西在GPU上时评估和修改theano张量

来自分类Dev

Python:并行化GPU和CPU工作

来自分类Dev

Hugin,多核CPU和可选GPU

来自分类Dev

CPU和GPU是否符合要求?

来自分类Dev

同一程序不同gpu结果精度不同

来自分类Dev

MAC使Theano使用GPU

来自分类Dev

spamassassin和spamc的结果不同

来自分类Dev

jQuery和JavaScript的不同结果

来自分类Dev

date()和gmdate()的结果不同

来自分类Dev

awk和nawk的结果不同

来自分类Dev

本地和分期的结果不同

来自分类Dev

不同 GPU 上的 Tensorflow 执行和内存

来自分类Dev

Theano退回到CPU