直接撸代码~
import caffe
import numpy as np caffe.set_mode_cpu()
net = caffe.Net('myprototxt.prototxt', 'mycaffemodel.caffemodel', caffe.TEST)
netNew = caffe.Net('myprototxt2.prototxt', 'mycaffemodel2.caffemodel', caffe.TEST)
for k, v in net.params.items():
#print (k, v[0].data.shape)
#print np.size(net.params[k])
for i in range(np.size(net.params[k])):
netNew.params[k][i].data[:] = np.copy(net.params[k][i].data[:])
params = {('layer_name_new','layer_name_old')}
for k, v in params:
for i in range(np.size(net.params[v])):
netNew.params[k][i].data[:] = np.copy(net.params[v][i].data[:])
netNew.save('mynewmodel.caffemodel')