运行代码时,收到一个值错误,并显示以下消息:
ValueError: Input dimension mis-match. (input[0].shape[1] = 1, input[2].shape[1] = 20)
Apply node that caused the error: Elemwise{Composite{((i0 + i1) - i2)}}[(0, 0)](Dot22.0, InplaceDimShuffle{x,0}.0, InplaceDimShuffle{x,0}.0)
Toposort index: 18
Inputs types: [TensorType(float64, matrix), TensorType(float64, row), TensorType(float64, row)]
Inputs shapes: [(20, 1), (1, 1), (1, 20)]
Inputs strides: [(8, 8), (8, 8), (160, 8)]
Inputs values: ['not shown', array([[ 0.]]), 'not shown']
Outputs clients: [[Elemwise{Composite{((i0 * i1) / i2)}}(TensorConstant{(1, 1) of 2.0}, Elemwise{Composite{((i0 + i1) - i2)}}[(0, 0)].0, Elemwise{mul,no_inplace}.0), Elemwise{Sqr}[(0, 0)](Elemwise{Composite{((i0 + i1) - i2)}}[(0, 0)].0)]]
我的培训数据是一个条目矩阵,比如。。在
^{pr2}$我输入到训练函数中的批处理的形状是(BATCH_SIZE,3)和typeTensorType(float64,matrix)
我的神经网络非常简单:
self.inpt = T.dmatrix('inpt')
self.out = T.dvector('out')
self.network_in = nnet.layers.InputLayer(shape=(BATCH_SIZE, 3), input_var=self.inpt)
self.l0 = nnet.layers.DenseLayer(self.network_in, num_units=40,
nonlinearity=nnet.nonlinearities.rectify,
)
self.network = nnet.layers.DenseLayer(self.l0, num_units=1,
nonlinearity=nnet.nonlinearities.linear
)
我的损失函数是:
pred = nnet.layers.get_output(self.network)
loss = nnet.objectives.squared_error(pred, self.out)
loss = loss.mean()
我有点困惑,为什么我得到一个尺寸不匹配。我传入了正确的输入和标签类型(根据我的符号变量),输入数据的形状对应于我给InputLayer的预期“shape”参数。我相信我如何指定批处理大小是个问题,因为当我使用批大小为1时,我的网络可以毫无问题地训练,错误消息中的输入[2].shape[1]值就是我的批大小。我对机器学习还不熟悉,任何帮助都将不胜感激!在
原来问题是我的标签有错误的维度。在
我的数据有形状:
我的网络的符号输入是:
^{pr2}$我通过改造火车来解决我的问题。然后,我将符号输出变量更改为矩阵来解释这些更改。在
相关问题 更多 >
编程相关推荐