caffemodel的读取与修改
直接撸代码~
1 import caffe 2 import numpy as np 3 4 caffe.set_mode_cpu() 5 net = caffe.Net('myprototxt.prototxt', 'mycaffemodel.caffemodel', caffe.TEST) 6 netNew = caffe.Net('myprototxt2.prototxt', 'mycaffemodel2.caffemodel', caffe.TEST) 7 for k, v in net.params.items(): 8 #print (k, v[0].data.shape) 9 #print np.size(net.params[k]) 10 for i in range(np.size(net.params[k])): 11 netNew.params[k][i].data[:] = np.copy(net.params[k][i].data[:]) 12 params = {('layer_name_new','layer_name_old')} 13 for k, v in params: 14 for i in range(np.size(net.params[v])): 15 netNew.params[k][i].data[:] = np.copy(net.params[v][i].data[:]) 16 netNew.save('mynewmodel.caffemodel')