我有一個庫(朱古力),其具有以下定義:類型錯誤的Python
class NetSpec(object):
def __init__(self):
super(NetSpec, self).__setattr__('tops', OrderedDict())
def __setattr__(self, name, value):
self.tops[name] = value
def __getattr__(self, name):
return self.tops[name]
def to_proto(self):
names = {v: k for k, v in self.tops.iteritems()}
autonames = {}
layers = OrderedDict()
for name, top in self.tops.iteritems():
top.fn._to_proto(layers, names, autonames)
net = caffe_pb2.NetParameter()
net.layer.extend(layers.values())
return net
當我嘗試調用使用n = caffe.NetSpec()
我收到以下錯誤時:
File "../../python/caffe/layers.py", line 84, in __init__
super(NetSpec, self).__setattr__('tops', OrderedDict())
TypeError: must be type, not None
我檢查SO-9698614 ,SO-576169和SO-489269但他們沒有導致解決方案。我的課是一個新的類型,我看不出爲什麼它不工作。
完整跟蹤:
Traceback (most recent call last):
File "<ipython-input-72-694741de221d>", line 1, in <module>
runfile('/home/shaunak/caffe-pr2086/examples/wine/classify.py', wdir='/home/shaunak/caffe-pr2086/examples/wine')
File "/home/shaunak/anaconda/lib/python2.7/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 682, in runfile
execfile(filename, namespace)
File "/home/shaunak/anaconda/lib/python2.7/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 78, in execfile
builtins.execfile(filename, *where)
File "/home/shaunak/caffe-pr2086/examples/wine/classify.py", line 26, in <module>
f.write(str(logreg('examples/hdf5_classification/data/train.txt', 10)))
File "/home/shaunak/caffe-pr2086/examples/wine/classify.py", line 18, in logreg
n = caffe.NetSpec()
File "../../python/caffe/layers.py", line 84, in __init__
super(NetSpec, self).__setattr__('tops', OrderedDict())
TypeError: must be type, not None
它適合我。 –
@MartijnPieters我重新檢查了跟蹤並取消了對庫的更改。錯誤仍然是:'超(NetSpec,個體經營).__ SETATTR __( '冠',OrderedDict())' - 更新代碼 – shaunakde
@shaunakde:你設置'NetSpec'到'None'地方?或者在模塊被清除時以其他方式運行此代碼? –