Is there being a way to modify/define the .proto file with python?

514 views
Skip to first unread message

Lynx Commando

unread,
Jun 14, 2017, 11:53:52 PM6/14/17
to Protocol Buffers
More specifically, I am using caffe and I'd like to add new layers to it.
Then I need to modify the caffe.proto file by adding(or removing) some messages and corresponding fields to some other messages.
I'd want to  know if I can do this automatically with a python script.

Bo Yang

unread,
Jun 15, 2017, 2:21:17 PM6/15/17
to Lynx Commando, Protocol Buffers
First, is caffe managed by yourself? Otherwise, I don't suggest change it by your own (may cause incompatibility issues).
Second, this seems like a python question instead of protobuf.

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To post to this group, send email to prot...@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Lynx Commando

unread,
Jun 16, 2017, 2:30:57 AM6/16/17
to Protocol Buffers, lynxco...@gmail.com

First, is caffe managed by yourself?
>No

Otherwise, I don't suggest change it by your own (may cause incompatibility issues).
>Unfortunately I have to....
Second, this seems like a python question instead of protobuf.
>What I want to know is that if protobuf has a python api making it easier.
>>More specifically , I am looking for something equivalent to a boost::xml_parser that parses xml
>> In another word, I want to know if there is somepkg allows me to do the following thing
>>> proto = somepkg.somecls.parse("src/caffe/caffe.proto")
>>> proto['LayerParameter'].append(somepkg.somecls.optional_field("MyNewParam","my_new_param",param_id))
>>> for fields in my_field_list:
>>>      proto['MyNewParam'].append(field)
>>> somepkg.somecls.write(proto,"src/caffe/caffe.proto")


Brian Palmer

unread,
Jun 21, 2017, 4:12:20 AM6/21/17
to Lynx Commando, Protocol Buffers
Hi,

it sounds to me like you should explore defining a new message that contains the LayerParameter as a field. For example,

syntax = "proto2";

package lynxcommando;

message AugmentedLayerParameter {
  optional caffe.LayerParameter base = 1;
  optional MyNewParameter my_new_parameter = 2;
}

message MyNewParameter {
  
};

Alternatively, you could ask the caffe authors to add in an extension range to their messages, so that you can do 

extend caffe.LayerParameter {
  optional MyNewParameter my_new_parameter = 12345;
}

As a last resort, there is support for creating "dynamic messages," but most of the examples I found searching around were doing it in java or c++. https://stackoverflow.com/questions/18836727/protocol-buffer-objects-generated-at-runtime  
  

To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+unsubscribe@googlegroups.com.

Bo Yang

unread,
Jun 21, 2017, 8:39:57 PM6/21/17
to Brian Palmer, Lynx Commando, Protocol Buffers
For option 2, I think you can extend caffe.LayerParameter by your self, given that LayerParameter allows extension.

Brian Palmer

unread,
Jun 21, 2017, 11:27:01 PM6/21/17
to Bo Yang, Lynx Commando, Protocol Buffers
Just peeking at https://github.com/BVLC/caffe/blob/master/src/caffe/proto/caffe.proto (which I'm guessing is the proto in question), I don't think it allows extension at the moment. 
Reply all
Reply to author
Forward
0 new messages