Error with to_proto(caffe-master/python/caffe/net_spec.py)-- 'LayerParameter' object has no attribute 'num_output'

993 views Asked by At

I'm trying to create the train.protxt of resnet with pycaffe and I got this error:

File "/data/hjy1312/Downloads/caffe-master/python/caffe/net_spec.py", line 140, in _to_proto
inp._to_proto(layers, names, autonames)
File "/data/hjy1312/Downloads/caffe-master/python/caffe/net_spec.py", line 97, in _to_proto
return self.fn._to_proto(layers, names, autonames)
File "/data/hjy1312/Downloads/caffe-master/python/caffe/net_spec.py", line 162, in _to_proto
assign_proto(layer, k, v)
File "/data/hjy1312/Downloads/caffe-master/python/caffe/net_spec.py", line 64, in assign_proto
is_repeated_field = hasattr(getattr(proto, name), 'extend')
AttributeError: 'LayerParameter' object has no attribute 'num_output'

after setting the breakpoint and running my code,i found the wrong with my code is this line:

from caffe import layers as L, params as P, to_proto  
return to_proto(acc, loss)

But I don't know what’s wrong with to_proto,could anyone help me?

Thank you very much!

1

There are 1 answers

1
Shai On

As you noted, you get the error when executing to_protot() function, but the error is not in the function itself, but rather in the inputs you provide.
Look at the error message you got

AttributeError: 'LayerParameter' object has no attribute 'num_output'

As one can understand from the error message, the net spec you provided has a layer (maybe more than one) that has num_output attribute for the layer itself (instead of an attribute to the layer's parameters).

In order to fix this error you need to inspect the code defining the layers and see that num_output is assigned to the layer params and not to the layer directly.