为什么我不能在theano中计算重塑的张量变量?

2024-04-26 08:12:41 发布

您现在位置:Python中文网/ 问答频道 /正文

为什么我不能通过我在下面写的代码来计算重塑的张量变量?你知道吗

from theano import shared
from theano import tensor as T
import numpy

x = T.matrix('x') # the input data

# input = (nImages, nChannel(nFeatureMaps), nDim1, nDim2, nDim3)

layer1_input = T.reshape(x, xTrain.shape, ndim=5)
layer1_input.eval({x:xTrain})

因为我已经重塑了张量变量x,并向它传递了一个相同维数的numpy数组,它只是报告

TypeError: ('Bad input argument to theano function with name ":17" at index 0(0-based)', 'Wrong number of dimensions: expected 2, got 5 with shape (2592, 1, 51, 61, 23).')


Tags: 代码fromimportnumpyinputaswiththeano
1条回答
网友
1楼 · 发布于 2024-04-26 08:12:41

我认为问题是因为您使用matrix(二维)作为x的数据类型,它接收一个五维输入xTrain。正如前面所说的here,对于五维输入,您应该创建一个自定义数据类型。你知道吗

示例代码:

from theano import tensor as T
import numpy as np
xTrain = np.random.rand(1,1,2,3,3).astype('float32')

dtensor5 = T.TensorType('float32', (False,)*5)
x = dtensor5('x')

layer1_input = x
print layer1_input.eval({x:xTrain})

关于

Since I have reshape the tensorvariable x, and pass a numpy array of same dimension to it

我认为实际发生的情况是变量x首先接收输入(引发错误),然后为layer1_input重塑它

相关问题 更多 >