【问题标题】:Shared variable indexing error in theanotheano中的共享变量索引错误
【发布时间】:2016-06-23 11:26:53
【问题描述】:

共享变量索引存在问题。

train_set_x的形状为(n, 3, 50176),n大于index

我可以使用以下代码从共享变量 train_set_x 中获取值

train_set_x.get_value(borrow=True)[index]

array([[ 143., 142., 142., ..., 141., 141., 145.], [ 114., 113., 113., ..., 141., 141., 145.], [ 108., 107., 107., ..., 139., 139., 143.]], dtype=float32)

但我无法通过以下代码获得价值

check = theano.function([index], x, givens = {x : train_set_x[index]})
check(index)

显示错误信息

*** IndexError: index out of bounds
Apply node that caused the error: GpuSubtensor{int64}(<CudaNdarrayType(float32, 3D)>, ScalarFromTensor.0)
Toposort index: 1
Inputs types: [CudaNdarrayType(float32, 3D), Scalar(int64)]
Inputs shapes: [(1039, 3, 50176), ()]
Inputs strides: [(150528, 50176, 1), ()]
Inputs values: ['not shown', 1039]
Outputs clients: [[HostFromGpu(GpuSubtensor{int64}.0)]]

HINT: Re-running with most Theano optimization disabled could give you a back-trace of when this node was created. This can be done with by setting the Theano flag 'optimizer=fast_compile'. If that does not work, Theano optimizations can be disabled with 'optimizer=None'.
HINT: Use the Theano flag 'exception_verbosity=high' for a debugprint and storage map footprint of this apply node.

它们之间有什么区别?以及将 train_set_x 中的值与 theano.function 一起使用的方法是什么?

【问题讨论】:

  • 什么是'x'?它应该是 dtype=float32 的 ftensor3()。
  • 'x' 是 theano.tensor.tensor3 变量。我尝试使用 ftensor3,但没有成功。

标签: indexing gpu theano


【解决方案1】:

Inputs values: ['not shown', 1039] 显示作为索引参数传递的值(它是 1039),Inputs shapes: [(1039, 3, 50176), ()] 行显示您的 n 是 1039。

所以看起来你真的像 theano 所说的那样越界了。 以下示例适用于我:

train_set_x = theano.shared(np.random.rand(10, 3, 3))
x = theano.tensor.matrix()
index = theano.tensor.iscalar()
check = theano.function([index], x, givens = {x : train_set_x[index]}
check(3)

虽然check(10) 显示非常相似的错误:

IndexError: index out of bounds
Apply node that caused the error: Subtensor{int32}(<TensorType(float64, 3D)>, ScalarFromTensor.0)
Toposort index: 1
Inputs types: [TensorType(float64, 3D), Scalar(int32)]
Inputs shapes: [(10, 3, 3), ()]
Inputs strides: [(72, 24, 8), ()]
Inputs values: ['not shown', 10]
Outputs clients: [[DeepCopyOp(Subtensor{int32}.0)]]

HINT: Use the Theano flag 'exception_verbosity=high' for a debugprint and storage map footprint of this apply node

【讨论】:

  • 你能解释一下为什么 check(10) 会抛出错误吗?给定示例中的样本数不是 10 吗?
  • @Shyamkkhadka,是的,10 是样本数,但索引从零开始,因此最后一个样本的索引为 9。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-08-21
  • 1970-01-01
  • 1970-01-01
  • 2013-10-29
  • 2016-02-28
  • 2023-03-18
  • 2015-09-30
相关资源
最近更新 更多