我正在研究openface。 Openface具有unknown classification python cod e。
我正在测试lfw-classification-unknown.py's
火车零件。
有训练使用
nolearn-DBN classifier
我安装了
nolearn version 0.5
。DBN classifier
具有对/usr/local/lib/python2.7/dist-packages/gnumpy.py
的函数调用,并且我有错误
File "/usr/local/lib/python2.7/dist-packages/gnumpy.py", line 738, in as_numpy_array
if self.size==0: return numpy.zeros(self.shape, dtype)
AttributeError: 'garray' object has no attribute 'size'
如何解决错误?
整个错误是
Traceback (most recent call last):
File "/usr/lib/python2.7/pdb.py", line 1314, in main
pdb._runscript(mainpyfile)
File "/usr/lib/python2.7/pdb.py", line 1233, in _runscript
self.run(statement)
File "/usr/lib/python2.7/bdb.py", line 400, in run
exec cmd in globals, locals
File "<string>", line 1, in <module>
File "evaluation/lfw-classification-unknown.py", line 519, in <module>
train(args)
File "evaluation/lfw-classification-unknown.py", line 130, in train
clf.fit(embeddings, labelsNum)
File "/usr/local/lib/python2.7/dist-packages/nolearn/dbn.py", line 409, in fit
self.use_dropout,
File "/usr/local/lib/python2.7/dist-packages/gdbn/dbn.py", line 202, in fineTune
err, outMB = step(inpMB, targMB, self.learnRates, self.momentum, self.L2Costs, useDropout)
File "/usr/local/lib/python2.7/dist-packages/gdbn/dbn.py", line 296, in stepNesterov
targetBatch = targetBatch if isinstance(targetBatch, gnp.garray) else gnp.garray(targetBatch)
File "/usr/local/lib/python2.7/dist-packages/gnumpy.py", line 735, in __new__
def __new__(cls, *args, **kwarg): return object.__new__(cls)
File "/usr/lib/python2.7/bdb.py", line 53, in trace_dispatch
return self.dispatch_return(frame, arg)
File "/usr/lib/python2.7/bdb.py", line 88, in dispatch_return
self.user_return(frame, arg)
File "/usr/lib/python2.7/pdb.py", line 190, in user_return
self.interaction(frame, None)
File "/usr/lib/python2.7/pdb.py", line 209, in interaction
self.print_stack_entry(self.stack[self.curindex])
File "/usr/lib/python2.7/pdb.py", line 900, in print_stack_entry
prompt_prefix)
File "/usr/lib/python2.7/bdb.py", line 381, in format_stack_entry
s = s + repr.repr(rv)
File "/usr/lib/python2.7/repr.py", line 24, in repr
return self.repr1(x, self.maxlevel)
File "/usr/lib/python2.7/repr.py", line 34, in repr1
s = __builtin__.repr(x)
File "/usr/local/lib/python2.7/dist-packages/gnumpy.py", line 1133, in __repr__
def __repr__(self): return self.as_numpy_array().__repr__().replace('array(', 'garray(').replace('\n', '\n ').replace(', dtype=float32', '').replace(', dtype=float64', '') # 64 happens for empty arrays
File "/usr/local/lib/python2.7/dist-packages/gnumpy.py", line 738, in as_numpy_array
if self.size==0: return numpy.zeros(self.shape, dtype)
AttributeError: 'garray' object has no attribute 'size'
> Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
> /usr/local/lib/python2.7/dist-packages/gnumpy.py(738)as_numpy_array()
-> if self.size==0: return numpy.zeros(self.shape, dtype)
编辑:
如果不在调试模式下,则错误如下。
Traceback (most recent call last):
File "evaluation/lfw-classification-unknown.py", line 519, in <module>
train(args)
File "evaluation/lfw-classification-unknown.py", line 130, in train
clf.fit(embeddings, labelsNum)
File "/usr/local/lib/python2.7/dist-packages/nolearn/dbn.py", line 407, in fit
self.use_dropout,
File "/usr/local/lib/python2.7/dist-packages/gdbn/dbn.py", line 202, in fineTune
err, outMB = step(inpMB, targMB, self.learnRates, self.momentum, self.L2Costs, useDropout)
File "/usr/local/lib/python2.7/dist-packages/gdbn/dbn.py", line 303, in stepNesterov
errSignals, outputActs, error = self.fpropBprop(inputBatch, targetBatch, useDropout)
File "/usr/local/lib/python2.7/dist-packages/gdbn/dbn.py", line 262, in fpropBprop
outputErrSignal = -self.outputActFunct.dErrordNetInput(targetBatch, self.state[-1], outputActs)
File "/usr/local/lib/python2.7/dist-packages/gdbn/activationFunctions.py", line 138, in dErrordNetInput
return acts - targets
File "/usr/local/lib/python2.7/dist-packages/gnumpy.py", line 965, in __sub__
else: return self + -as_garray(other) # if i need to broadcast, making use of the row add and col add methods is probably faster
File "/usr/local/lib/python2.7/dist-packages/gnumpy.py", line 926, in __add__
def __add__(self, other): return _check_number_types(self._broadcastable_op(as_garray_or_scalar(other), 'add'))
File "/usr/local/lib/python2.7/dist-packages/gnumpy.py", line 614, in _broadcastable_op
if reduce(operator.or_, ( other.shape[i] not in (1, self.shape[i]) for i in range(self.ndim)), False): raise ValueError('shape mismatch: objects cannot be broadcast to a single shape')
ValueError: shape mismatch: objects cannot be broadcast to a single shape
最佳答案
您还没有发布任何实际的代码,因此实际上不可能确切知道您的问题是什么。
编辑
从堆栈跟踪中可以清楚地看到,您遇到的问题是由于pdb
试图在调用garray
之后立即获取并打印garray.__new__
的值所致。这是在调用__init__
之前,因此.size
属性尚不存在。
似乎在__new__
代码中甚至没有必要重新定义gnumpy.garray
,因此您可以通过打开/usr/local/lib/python2.7/dist-packages/gnumpy.py
然后注释掉第735行(即带有__new__
的定义)。
更简单的是,如果不使用pdb
(例如python lfw-classification-unknown.py
)仅运行脚本,会发生什么情况?似乎此特定错误将消失。另一方面,您可能最初是出于实际原因使用调试器的。您最初是否遇到其他错误?在这种情况下,这是一个XY problem,您应该只发布一个新问题,询问原始错误。
不幸的是,gnumpy.garray
需要运行真正的NVidia GPU,而我没有,所以我不能直接测试这些解决方案。
一般问题
话虽这么说,似乎在不设置garray
属性的情况下以某种方式创建了.size
对象。这可能是由于您自己的代码或4个不同软件包(openface
加3个依赖项)中的任何一个错误所致。这是一个大概的概述。openface
对nolearn
具有依赖关系,而gbdn
对gnumpy
具有依赖关系。详细地:
链接到的openface
代码在a dependency上具有the nolearn.dbn.DBN
class。
has a dependency上的nolearn.dbn.DBN
the gdbn.dbn.buldDBN
function,并通过它gdbn.dbn.DBN
class。gdbn.dbn.buldDBN
和gdbn.dbn.DBN
都有创建class gnumpy.garray
数组的代码
因此,大概是由于在garrays
或buildDBN
中创建DBN
之一而搞砸了。仅在调用the .size
method时设置gnumpy.garray._set_shape_info
属性。粗略地查看garray
的实现并没有发现在初始化期间无法调用_set_shape_info
的任何明显方式。但是,确实跳出来的一件事是,至少有十几种不同的代码路径可能会导致garray
的初始化。如果有一个边缘情况在不调用_set_shape_info
的情况下滑过,这也就不足为奇了。
关于python - 使用nolearn-DBN分类器,“garray”对象没有属性“size”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54158005/