-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_caffe_model.py
More file actions
53 lines (26 loc) · 968 Bytes
/
read_caffe_model.py
File metadata and controls
53 lines (26 loc) · 968 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
import caffe
import numpy as np
np.set_printoptions(threshold='nan')
#MODEL_FILE = '/home/qd/code/point5/facialkp_predict.prototxt'
#PRETRAIN_FILE = '/home/qd/code/point5/tmp_iter_2000.caffemodel'
MODEL_FILE = '/home/qd/caffe/examples/mnist/lenet.prototxt'
PRETRAIN_FILE = '/home/qd/caffe/examples/mnist/lenet_iter_10000.caffemodel'
params_txt = '/home/qd/code/point5/params2.txt'
pf = open(params_txt, 'w')
net = caffe.Net(MODEL_FILE, PRETRAIN_FILE, caffe.TEST)
for param_name in net.params.keys():
weight = net.params[param_name][0].data
bias = net.params[param_name][1].data
pf.write(param_name)
pf.write('\n')
pf.write('\n' + param_name + '_weight:\n\n')
weight.shape = (-1, 1)
for w in weight:
pf.write('%ff, ' % w)
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