Copying the weights of caffe layer partially

33 views
Skip to first unread message

kiana ehsani

unread,
Oct 24, 2016, 7:00:54 PM10/24/16
to Caffe Users
I am working on VGG16 network and I want to finetune this network for my data. The problem is that my input has one extra channel. So the original VGG gets the input of shape 3x224x224, but my input is of shape 4x224x224. 

I can not use the weights for the regular VGG16 because the first layer (conv1_1) was supposed to have 3 channels but mine has 4. 

So the problem can be partially solved if I randomly initialize the first layer and copy the weights for the rest of the network. But this will not solve my problem in a perfect way.

What I want to do now is to copy the weights for the first layer for those three channels and randomly initialize the rest of the first layer for the new fourth channel. But this I mean I wanna copy the weights of some parts of a layer and initialize the rest of that layer randomly. Is there a way to do so in Caffe?

Hieu Do Trung

unread,
Oct 24, 2016, 11:39:57 PM10/24/16
to Caffe Users
https://github.com/BVLC/caffe/blob/master/examples/net_surgery.ipynb

There you can see how a layer's parameters are modified.
(this part onward:
 In [5]:
ksize = net.params['conv'][0].data.shape[2:]
Reply all
Reply to author
Forward
0 new messages