问题
Why can't I evaluate the reshaped tensorvariable through the code I wrote below?
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})
Since I have reshape the tensorvariable x, and pass a numpy array of same dimension to it, it simply reports,
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).')
回答1:
I think the problem is because you are using matrix
(two dimensional) as data type of x
that receive a five dimensional input xTrain
. As said here, for five dimensional input, you should create a custom data type.
sample code:
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})
and about
Since I have reshape the tensorvariable x, and pass a numpy array of same dimension to it
I think what actually happen is variable x
recieve the input first (raise an error) and then you reshape it for layer1_input
来源:https://stackoverflow.com/questions/36312253/why-cant-i-evaluate-the-reshaped-tensorvariable-in-theano