gpt4 book ai didi

python - 为什么我无法在 theano 中评估 reshape 的张量变量?

转载 作者:太空宇宙 更新时间:2023-11-03 16:45:51 25 4
gpt4 key购买 nike

为什么我无法通过下面编写的代码来评估 reshape 后的张量变量?

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})

由于我已经 reshape 了张量变量 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).')

最佳答案

我认为问题是因为您使用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 reshape 它

关于python - 为什么我无法在 theano 中评估 reshape 的张量变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36312253/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com