python的性质使我很难找到一种正式的定义,如何调用theano函数。
当给出长度为4的矩阵batch的列表时,我调用
validationFunction(batch[0],batch[1],batch[2],batch[3])而且这个很管用。
当我打电话的时候
validationFunction(batch)或
validationFunction((list(batch))它抱怨说:
validationError += validationFunction(batch) # [0],batch[1], batch[2], batch[3])
File "/usr/lib64/python2.7/site-packages/theano/compile/function_module.py", line 786, in __call__
allow_downcast=s.allow_downcast)
File "/usr/lib64/python2.7/site-packages/theano/tensor/type.py", line 149, in filter
converted_data = theano._asarray(data, self.dtype)
File "/usr/lib64/python2.7/site-packages/theano/misc/safe_asarray.py", line 33, in _asarray
rval = numpy.asarray(a, dtype=dtype, order=order)
File "/usr/lib64/python2.7/site-packages/numpy/core/numeric.py", line 474, in asarray
return array(a, dtype, copy=False, order=order)
ValueError: ('Bad input argument to theano function with name "dummy.py:96" at index 0(0-based)', 'could not broadcast input array from shape (7,3) into shape (7)')我有一个符号输入变量列表和一个相应的小型批次列表。批处理形式为:print(“批处理单数=\n0:{}\n1:{}\n2:{}\n3:}”.format( Batch,batch1,batch2,batch3))
0:[[3.0 3.0 2.0]
[3.0 2.0 5.0]
[2.0 5.0 3.0]
[5.0 3.0 4.0]
[3.0 4.0 3.0]
[4.0 3.0 2.0]
[3.0 2.0 6.0]]
1:[[5.0 3.0 4.0]
[3.0 4.0 3.0]
[4.0 3.0 2.0]
[3.0 2.0 6.0]
[2.0 6.0 6.0]
[6.0 6.0 6.0]
[6.0 6.0 2.0]]
2:[[3.0 2.0 14.0]
[2.0 2.0 14.0]
[6.0 2.0 14.0]
[6.0 2.0 14.0]
[6.0 2.0 14.0]
[2.0 2.0 14.0]
[4.0 2.0 14.0]]
3:[[2.0]
[6.0]
[6.0]
[6.0]
[2.0]
[4.0]
[4.0]]基本上,如果没有硬编码1.n,我如何调用validationFunction(a,a1,.,an-1)?争论的定义是什么?
函数被定义为
validationFunction= theano.function(inputVars + [targetVar], testLoss)其中inputVars是theano矩阵的列表,targetVar是theano矩阵。我应该以不同的方式定义函数吗?inputVars + [targetVar]创建了我的三个输入和一个目标的列表。
我真的花了很多时间在西亚诺和它的风格上,但是有些东西被记录得太紧凑了。
输入可以作为变量或在实例中给出。在实例中也有一个变量,但它们附加了一些关于如何使用与该变量对应的调用时参数的额外信息。类似地,Out实例可以附加关于如何返回输出变量的信息。
发布于 2016-05-02 19:09:59
我在这个stackoverflow中找到了解决方案,我只需将其命名为:
validationFunction(*batch)而不是
validationFunction(batch)哦,天哪,我学到的蟒蛇越多,我就越喜欢那些冗长的模板声明和从java定义东西的接口。
https://stackoverflow.com/questions/36989365
复制相似问题