来自 theano 的 TypeError 使用 3D numpy 数组时
TypeError from theano While using 3D numpy array
我正在尝试类似于下面的代码
datax=theano.shared(value=rng.rand(5,500,45))
x=T.dmatrix('x')
i=T.lscalar('i')
W=theano.shared(value=rng.rand(90,45,500))
Hb=theano.shared(value=np.zeros(90))
w_v_bias=T.dot(W,x).sum(axis=2).sum(axis=1)+Hb
z=theano.function([i],w_v_bias,givens={x:datax[i*5:(i+1)*5]})
z(0)
Theano 给我一个 TypeError 消息:
Cannot convert Type TensorType(float64, 3D) (of Variable Subtensor{int64:int64:}.0) into Type TensorType(float64, matrix). You can try to manually convert Subtensor{int64:int64:}.0 into a TensorType(float64, matrix)
我做错了什么?
编辑
如 daniel 所述,将 x 更改为 dtensor3 将导致另一个错误。
ValueError: Input dimension mis-match. (input[0].shape[1] = 5, input[1].shape[1] = 90)
Apply node that caused the error: Elemwise{add,no_inplace}(Sum{axis=[1], acc_dtype=float64}.0, DimShuffle{x,0}.0)
另一种方法是修改我的训练函数,但那样我将无法进行批量学习。
z=theano.function([x],w_v_bias)
z(datax[0])
我正在尝试使用可见单位的整数值实现 RBM。
问题是 datax
是一个 3D 张量,datax[index*5:(index+1)*5]
也是一个 3D 张量,但您试图将其分配给 x
,这是一个 2D 张量(即一个矩阵)。
改变
x = T.dmatrix('x')
到
x = T.dtensor3('x')
解决了这个问题,但创建了一个新问题,因为 W 和 x 的维度不匹配,无法执行点积。目前还不清楚期望的结果是什么。
经过几次尝试后解决了。
我需要的是改变
x=T.dmatrix('x')
w_v_bias=T.dot(W,x).sum(axis=2).sum(axis=1)+Hb
到
x=T.dtensor3('x')
w_v_bias=T.dot(x,W).sum(axis=3).sum(axis=1)+Hb
现在它在将 Hb 元素添加到点积的五个向量中的每一个之后生成 (5,90) 数组。
我正在尝试类似于下面的代码
datax=theano.shared(value=rng.rand(5,500,45))
x=T.dmatrix('x')
i=T.lscalar('i')
W=theano.shared(value=rng.rand(90,45,500))
Hb=theano.shared(value=np.zeros(90))
w_v_bias=T.dot(W,x).sum(axis=2).sum(axis=1)+Hb
z=theano.function([i],w_v_bias,givens={x:datax[i*5:(i+1)*5]})
z(0)
Theano 给我一个 TypeError 消息:
Cannot convert Type TensorType(float64, 3D) (of Variable Subtensor{int64:int64:}.0) into Type TensorType(float64, matrix). You can try to manually convert Subtensor{int64:int64:}.0 into a TensorType(float64, matrix)
我做错了什么?
编辑
如 daniel 所述,将 x 更改为 dtensor3 将导致另一个错误。
ValueError: Input dimension mis-match. (input[0].shape[1] = 5, input[1].shape[1] = 90)
Apply node that caused the error: Elemwise{add,no_inplace}(Sum{axis=[1], acc_dtype=float64}.0, DimShuffle{x,0}.0)
另一种方法是修改我的训练函数,但那样我将无法进行批量学习。
z=theano.function([x],w_v_bias)
z(datax[0])
我正在尝试使用可见单位的整数值实现 RBM。
问题是 datax
是一个 3D 张量,datax[index*5:(index+1)*5]
也是一个 3D 张量,但您试图将其分配给 x
,这是一个 2D 张量(即一个矩阵)。
改变
x = T.dmatrix('x')
到
x = T.dtensor3('x')
解决了这个问题,但创建了一个新问题,因为 W 和 x 的维度不匹配,无法执行点积。目前还不清楚期望的结果是什么。
经过几次尝试后解决了。
我需要的是改变
x=T.dmatrix('x')
w_v_bias=T.dot(W,x).sum(axis=2).sum(axis=1)+Hb
到
x=T.dtensor3('x')
w_v_bias=T.dot(x,W).sum(axis=3).sum(axis=1)+Hb
现在它在将 Hb 元素添加到点积的五个向量中的每一个之后生成 (5,90) 数组。