look_weight
look_weight
#-*-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 = "centerloss_bwn_all/face_deploy.prototxt" PRETRAIN_FILE = "centerloss_bwn_all/model/centerloss_bwn_all_iter_100000.caffemodel" #process params_txt = 'centerloss_bwn_all/centerloss_bwn_all_100000_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