Use the same name in two branches' net in order to finetune.

340 views
Skip to first unread message

Jobs Bill

unread,
Jan 1, 2016, 7:37:11 AM1/1/16
to Caffe Users
Hi, everyone.

I have a two branches's net and want each of them to finetune from caffenet independently. Then, I will connect them in FC layer.
According to caffe's guide, I should set the layer's name being same as caffenet. There is two branches, so I have to set two same 
name layer in one net(such as two conv1, two conv2, etc). But, when I draw the net with caffe's python scripts , there seems something 
wrong with my net, the net is cross at the layer with the same name, i.e. the net recognizes the same name's layers  as the same layer(
actually they are in different branches).
I think caffe handle the layer by name and in order, so since the two conv1 in different index, it is OK with same name. Am I wrong?
Any suggestion will be appreciate.

Thanks.

Neil Nelson

unread,
Jan 1, 2016, 10:45:00 AM1/1/16
to Caffe Users
Looks like a simple option to try will be to preface the names of the layers in the two separate branches with, for example, 'a_' for one and 'b_' for the other.

Jobs Bill

unread,
Jan 2, 2016, 6:36:53 AM1/2/16
to Caffe Users
Could you please figure out which option is it? I have never heard this before, all I know is something like siamese net, but it seems not helpful for this problem.
Thank you!
在 2016年1月1日星期五 UTC+8下午11:45:00,Neil Nelson写道:

Neil Nelson

unread,
Jan 2, 2016, 11:27:34 AM1/2/16
to Caffe Users
Jobs,

From the Siamese Net page we have

### Building the Second Side of the Siamese Net

Now we need to create the second path that operates on `data_p` and produces
`feat_p`. This path is exactly the same as the first. So we can just copy and
paste it. Then we change the name of each layer, input, and output by appending
`_p` to differentiate the "paired" layers from the originals.

Looks like the only option is to have unique layer names. Siamese Net appends its second path with '_p' to makes its names different from the first path.

Jobs Bill

unread,
Jan 2, 2016, 9:14:42 PM1/2/16
to Caffe Users
Thank you, Nelson. When I add the suffix, only one branch can be finetuned from CaffeNet because only this branch have the same name with CaffeNet's layers names.
Caffe finetunes net when their layer's name is same, this is what that confuses me. When I set two branches's layer name be same, there is only one layer in net shared by two branches(like conv1,even though I actually write two of them in different branches in train prototxtfile), when I add suffix in the other side of the net's layer name(like conv1_g), only one branches can do the finetune job.

在 2016年1月3日星期日 UTC+8上午12:27:34,Neil Nelson写道:

Evan Shelhamer

unread,
Jan 10, 2016, 8:54:59 PM1/10/16
to Jobs Bill, Caffe Users
Tricky initializations can be done by net surgery in Python: http://nbviewer.ipython.org/github/BVLC/caffe/blob/master/examples/net_surgery.ipynb

Once CaffeNet and your new architecture are loaded at the same time, you can assign parameters from one to the other and then save your initial model weights as a .caffemodel to begin training from.

I often make scripts to do net surgery and training all in one to streamline experiments.

Evan Shelhamer





--
You received this message because you are subscribed to the Google Groups "Caffe Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to caffe-users...@googlegroups.com.
To post to this group, send email to caffe...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/caffe-users/ba18392d-d028-4193-a29b-90970c9b4a88%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Jobs Bill

unread,
Jan 11, 2016, 8:10:21 AM1/11/16
to Caffe Users, baole...@gmail.com
Dear Evan,

Thank you very much. I have tried as your guide, it was amazing to do net surgery with pycaffe.

But, after finetuneing initial model weights's caffemodel, my training loss curve is the same as the net which I use two same name layer(conv1,conv2,conv3,conv4,conv5,conv1,conv2,conv3,conv4,conv5,fc6...) for finetuneing CaffeNet. 
In caffe net.cpp, I see the layer_id is used. So I guess it is also OK to do finetuning like my "two same name layer in one net", since they have different layer_id even though they share name. The problem is draw_net.py deals net with
the layer name, therefore, when I use draw_net.py to draw my net, the net crosses at conv1, conv2, ...,conv5.

在 2016年1月11日星期一 UTC+8上午9:54:59,Evan Shelhamer写道:
Reply all
Reply to author
Forward
0 new messages