TypeError:不兼容的可广播尺寸。预期(假,),得到(真,)

时间:2017-06-05 09:57:11

标签: python theano lasagne batch-normalization

我正在和theano和烤宽面条一起工作。

我正在尝试使用BatchNorm,我收到此错误。有人可以指导我,可能有什么不对吗?或者,如果我可以获得具有此不匹配的变量的名称?

谢谢!

EDIT1:

我正在尝试做这样的事情:

inputTarget = lasagne.layers.InputLayer(shape=(1,2,32, 32, 32), input_var=T.concatenate([tX, tY], axis=1))
network = lasagne.layers.SliceLayer(inputTarget, indices=slice(0, 1),axis=1) 
tX_new = lasagne.layers.get_output(network)
network = lasagne.layers.batch_norm(network)
tY_predicted = lasagne.layers.get_output(network)
target= lasagne.layers.SliceLayer(inputTarget, indices=slice(1, None), axis=1)  

tY_new = lasagne.layers.get_output(target)
loss = lasagne.objectives.squared_error(tY_predicted, tY_new).mean()
updates = lasagne.updates.adam(loss, params, learning_rate=lr)
train_fn = theano.function([tX, tY], [tY_predicted, loss, tY_new, tX_new], updates=updates)

日志:

Traceback (most recent call last):
  train_fn = theano.function([tX, tY], [tY_predicted, loss, tY_new, tX_new], updates=updates)
  File "/lib/python2.7/site-packages/theano/compile/function.py", line 326, in function
    output_keys=output_keys)
  File "/lib/python2.7/site-packages/theano/compile/pfunc.py", line 449, in pfunc
    no_default_updates=no_default_updates)
  File "/lib/python2.7/site-packages/theano/compile/pfunc.py", line 219, in rebuild_collect_shared
    cloned_v = clone_v_get_shared_updates(v, copy_inputs_over)
  File "/lib/python2.7/site-packages/theano/compile/pfunc.py", line 93, in clone_v_get_shared_updates
    clone_v_get_shared_updates(i, copy_inputs_over)
  File "/lib/python2.7/site-packages/theano/compile/pfunc.py", line 93, in clone_v_get_shared_updates
    clone_v_get_shared_updates(i, copy_inputs_over)
  File "/lib/python2.7/site-packages/theano/compile/pfunc.py", line 219, in rebuild_collect_shared
    cloned_v = clone_v_get_shared_updates(v, copy_inputs_over)
  File "/lib/python2.7/site-packages/theano/compile/pfunc.py", line 93, in clone_v_get_shared_updates
    clone_v_get_shared_updates(i, copy_inputs_over)
  File "/lib/python2.7/site-packages/theano/compile/pfunc.py", line 93, in clone_v_get_shared_updates
    clone_v_get_shared_updates(i, copy_inputs_over)
  File "/lib/python2.7/site-packages/theano/compile/pfunc.py", line 93, in clone_v_get_shared_updates
    clone_v_get_shared_updates(i, copy_inputs_over)
  File "/lib/python2.7/site-packages/theano/compile/pfunc.py", line 93, in clone_v_get_shared_updates
    clone_v_get_shared_updates(i, copy_inputs_over)
  File "/lib/python2.7/site-packages/theano/compile/pfunc.py", line 93, in clone_v_get_shared_updates
    clone_v_get_shared_updates(i, copy_inputs_over)
  File "/lib/python2.7/site-packages/theano/compile/pfunc.py", line 93, in clone_v_get_shared_updates
    clone_v_get_shared_updates(i, copy_inputs_over)
  File "/lib/python2.7/site-packages/theano/compile/pfunc.py", line 93, in clone_v_get_shared_updates
    clone_v_get_shared_updates(i, copy_inputs_over)
  File "/lib/python2.7/site-packages/theano/compile/pfunc.py", line 93, in clone_v_get_shared_updates
    clone_v_get_shared_updates(i, copy_inputs_over)
  File "/lib/python2.7/site-packages/theano/compile/pfunc.py", line 114, in clone_v_get_shared_updates
    allow_convert=False)
  File "/lib/python2.7/site-packages/theano/sandbox/cuda/type.py", line 185, in filter_variable
    str(self.broadcastable)))
TypeError: Incompatible broadcastable dimensions. Expected (False,), got (True,).

检查变量后,我知道代码中断了。我无法弄清楚原因。

1 个答案:

答案 0 :(得分:0)

Theano不会像numpy那样进行广播(自动)。您必须手动设置可广播所需的维度。有一个关于广播here的惊人教程。如果您在完成本教程后问题仍然存在,请与我分享您的代码和完整的追溯,以便我们进一步帮助您。