共享变量索引存在问题。
train_set_x的形状为(n,3,50176),n大于索引
我可以使用以下代码
从共享变量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.
他们之间有什么区别?什么是使用theano.function中的train_set_x中的值的方法?
答案 0 :(得分:0)
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