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)')
我有一个符号输入变量列表和相应的minibatches列表 . 批处理的格式为:print(“batch singular = \ n0:{} \ n1:{} \ n2:{} \ n3:{}” . format(批处理[0],批处理[1],批处理[2]分批[3]))
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 [0],a [1],...,a [n-1])?参数的定义是什么?
该功能已定义
validationFunction= theano.function(inputVars + [targetVar], testLoss)
其中inputVars是theano矩阵的列表,targetVar是theano矩阵 . 我应该以不同的方式定义功能吗? inputVars + [targetVar]
创建了我的三个输入和一个目标的列表 .
我真的花了很多时间与theano及其风格,但有些东西记录得太紧凑了 .
输入可以作为变量或In实例给出 . 在实例中也有一个变量,但是它们附加了一些关于应该如何使用与该变量对应的调用时参数的额外信息 . 同样,Out实例可以附加有关如何返回输出变量的信息 .
1 回答
我在stackoverflow找到了解决方案,我只需要调用它:
代替
哦,亲爱的,我学到的python越多,我就越开始喜欢所有那些详细的样板声明和界面定义来自java的东西 .