Is there a simple way of renaming layers in a caffe network by using the pycaffe interface?
I have looked through the net surgery example, but I cannot find an example of what I need.
For example, I would like to load a trained Caffe model and change the name of conv1
layer and its corresponding blob to new-conv1
.
I don't know a direct way to do it, but here is a workaround:
Given a pretrained Caffe model my_model.caffemodel
and its net architecture net.prototxt
. Make a copy of net.prototxt
(say net_new.prototxt
), and change the name of conv1
layer to new-conv1
(you can change the names of bottom
and top
if you want).
import caffe
net_old = caffe.Net('net.prototxt','my_model.caffemodel',caffe.TEST)
net_new = caffe.Net('net_new.prototxt','my_model.caffemodel',caffe.TEST)
net_new.params['new-conv1'][0].data[...] = net_old.params['conv1'][0].data[...] #copy filter across 2 nets
net_new.params['new-conv1'][1].data[...] = net_old.params['conv1'][1].data[...] #copy bias
net_new.save('my_model_new.caffemodel')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With