【问题标题】:(Lasagne) ValueError: Input dimension mis-match(千层面)ValueError:输入尺寸不匹配
【发布时间】:2017-08-02 03:00:50
【问题描述】:

当我运行我的代码时,我收到带有以下消息的值错误:

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

我的训练数据是一个条目矩阵,例如 ..

[ 815.257786    320.447   310.841]

我输入到训练函数的批次的形状为 (BATCH_SIZE, 3) 并输入 TensorType(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 的预期“形状”参数。我相信这是我如何指定批量大小的问题,因为当我使用批量大小为 1 时,我的网络可以毫无问题地进行训练,并且错误消息中的 input[2].shape[1] 值为我的批量大小。我对机器学习很陌生,任何帮助都将不胜感激!

【问题讨论】:

    标签: python machine-learning deep-learning theano lasagne


    【解决方案1】:

    原来问题是我的标签有错误的维度。

    我的数据有形状:

    x_train.shape == (batch_size, 3)
    y_train.shape == (batch_size,)
    

    我的网络的符号输入是:

    self.inpt = T.dmatrix('inpt')
    self.out  = T.dvector('out')
    

    我能够通过重塑 y_train 来解决我的问题。然后我将符号输出变量更改为矩阵以说明这些变化。

    y_train = np.reshape(y_train, y_train.shape + (1,))
    # y_train.shape == (batch_size, 1)
    
    self.out = T.dmatrix('out')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多