Why can't I evaluate the reshaped tensorvariable in theano?

二次信任 提交于 2019-12-13 02:59:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!