查看参数值的代码
#-*-coding:utf-8-*-
import caffe
import sys
import numpy as np
import getopt
import re
if __name__ =="__main__":
opts,args = getopt.getopt(sys.argv[1:],"m:w:")
MODEL_FILE = "test-13.prototxt"
PRETRAIN_FILE = "n36_faster_rcnn__binarizedmodel_svd_fc6_512_fc7_512.caffemodel"
#process
params_txt = 'params.txt'
pf = open(params_txt, 'w')
print MODEL_FILE
print PRETRAIN_FILE
net = caffe.Net
(MODEL_FILE, PRETRAIN_FILE, caffe.TEST)
for param_name in net.params.keys():
if re.match('conv.',param_name) or re.match('fc.',param_name):
print 'zhaodezan'
weight = net.params[param_name][0].data
bias = net.params[param_name][1].data
#保存开始
pf.write(param_name)
pf.write('\n')
#保存weight
pf.write('\n' + param_name + '_weight:\n\n')
weight.shape = (-1, 1)
for w in weight:
pf.write('%ff, ' % w)
#保存bias
pf.write('\n\n' + param_name + '_bias:\n\n')
bias.shape = (-1, 1)
for b in bias:
pf.write('%ff, ' % b)
pf.write('\n\n')
pf.close