Fix protobuf message generation
authorThomas <twatson52@mac.com>
Mon, 11 Apr 2016 17:52:34 +0000 (12:52 -0500)
committerThomas <twatson52@mac.com>
Mon, 11 Apr 2016 17:52:34 +0000 (12:52 -0500)
The latest versions of protobuf do not reveal empty message fields with dir(). This uses the documented way of determining all of a message's fields and so is compatible with past and future versions of protobuf.

python/caffe/net_spec.py

index 63de4cc..5fb1f0b 100644 (file)
@@ -32,7 +32,7 @@ def param_name_dict():
     # get all parameter names (typically underscore case) and corresponding
     # type names (typically camel case), which contain the layer names
     # (note that not all parameters correspond to layers, but we'll ignore that)
-    param_names = [s for s in dir(layer) if s.endswith('_param')]
+    param_names = [f.name for f in layer.DESCRIPTOR.fields if f.name.endswith('_param')]
     param_type_names = [type(getattr(layer, s)).__name__ for s in param_names]
     # strip the final '_param' or 'Parameter'
     param_names = [s[:-len('_param')] for s in param_names]