永发信息网

如何导出caffemodel参数

答案:2  悬赏:20  手机版
解决时间 2021-03-20 16:36
  • 提问者网友:龅牙恐龙妹
  • 2021-03-20 04:09
如何导出caffemodel参数
最佳答案
  • 五星知识达人网友:天凉才是好个秋
  • 2021-03-20 05:28
可以直接读取caffemodel中的模型参数
全部回答
  • 1楼网友:撞了怀
  • 2021-03-20 06:21
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…
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯