为什么我不能评估theano中的重塑张量? [英] Why can't I evaluate the reshaped tensorvariable in theano?
问题描述
为什么我不能通过下面编写的代码来评估重塑后的张量变量?
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})
由于我已经调整了张量变量x的形状,并向其传递了一个相同维的numpy数组,所以它只是报告,
Since I have reshape the tensorvariable x, and pass a numpy array of same dimension to it, it simply reports,
TypeError:('theano函数的输入参数名称错误 :17"位于索引0(从0开始)','错误 尺寸数量:预期2,得到5个形状(2592、1、51、61, 23).')
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).')
推荐答案
我认为问题是因为您使用matrix
(二维)作为x
的数据类型而接收到五维输入xTrain
.如此处所述,对于五维输入,您应该创建一个自定义数据类型.
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.
示例代码:
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})
关于
由于我已经调整了张量变量x的值,并传递了一个numpy数组 尺寸相同
Since I have reshape the tensorvariable x, and pass a numpy array of same dimension to it
我认为实际发生的情况是变量x
首先接收输入(引发错误),然后为layer1_input
对其进行整形
I think what actually happen is variable x
recieve the input first (raise an error) and then you reshape it for layer1_input
这篇关于为什么我不能评估theano中的重塑张量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!