如何导出caffemodel参数

 我来答
zo...9@sina.com
2016-12-17 · TA获得超过172个赞
知道小有建树答主
回答量:631
采纳率:0%
帮助的人:311万
展开全部
import scipy.io as sio
import caffe

def load():
# Load the net
caffe.set_mode_cpu()
# You may need to train this caffemodel first
# There should be script to help you do the training
net = caffe.Net(root + 'lenet.prototxt', root + 'lenet_iter_10000.caffemodel',\
caffe.TEST)
conv1_w = net.params['conv1'][0].data
conv1_b = net.params['conv1'][1].data
conv2_w = net.params['conv2'][0].data
conv2_b = net.params['conv2'][1].data
ip1_w = net.params['ip1'][0].data
ip1_b = net.params['ip1'][1].data
ip2_w = net.params['ip2'][0].data
ip2_b = net.params['ip2'][1].data
sio.savemat('conv1_w', {'conv1_w':conv1_w})
sio.savemat('conv1_b', {'conv1_b':conv1_b})
sio.savemat('conv2_w', {'conv2_w':conv2_w})
sio.savemat('conv2_b', {'conv2_b':conv2_b})
sio.savemat('ip1_w', {'ip1_w':ip1_w})
sio.savemat('ip1_b', {'ip1_b':ip1_b})
sio.savemat('ip2_w', {'ip2_w':ip2_w})
sio.savemat('ip2_b', {'ip2_b':ip2_b})

if __name__ == "__main__":
# You will need to change this path
root = '/Users/yuliangzou/caffe-rc3/examples/mnist/'
load()
print 'Caffemodel loaded and written to .mat files successfully!'

从代码里可以看得很清楚啦,首先导入模型,然后利用net.params就可以获取参数了,另外你也可以利用net.data导出数据进行可视化。当然,在导出参数之前…你必须要跑过一遍,不然你没有这个caffemodel…
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式