-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcnnWeight.m
83 lines (73 loc) · 1.66 KB
/
cnnWeight.m
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
function weight = cnnWeight(weightFile)
% read the CNN weight from the file
fid = fopen(weightFile);
lineData = fscanf(fid, '%f',[1,inf]);
fclose(fid);
idx = 0;
% conv 1 weight 16*1*5*5
conv1Weight = zeros(5,5,16,1); % easy to get the sub matrix in this model
for i = 1:16
for j = 1:1
for m = 1:5
for n = 1:5
idx = idx +1;
conv1Weight(m,n,i,j) = lineData(idx);
end
end
end
end
% conv 1 bias 16
for i = 1:16
idx = idx + 1;
conv1Bias(i) = lineData(idx);
end
% conv 4 weight 32*16*5*5
conv4Weight = zeros(5,5,32,16); % easy to get the sub matrix in this model
for i = 1:32
for j = 1:16
for m = 1:5
for n = 1:5
idx = idx +1;
conv4Weight(m,n,i,j) = lineData(idx);
end
end
end
end
% conv 4 bias 32
for i = 1:32
idx = idx + 1;
conv4Bias(i) = lineData(idx);
end
% linear 8 weight 256*800
for i = 1:256
for j = 1:800
idx = idx + 1;
linear8Weight(i,j) = lineData(idx);
end
end
% linear 8 bias 256
for i = 1:256
idx = idx + 1;
linear8Bias(i) = lineData(idx);
end
% linear 10 weight 43*256
for i = 1:43
for j = 1:256
idx = idx + 1;
linear10Weight(i,j) = lineData(idx);
end
end
% linear 10 bias 43
for i = 1:43
idx = idx + 1;
linear10Bias(i) = lineData(idx);
end
% merge all weight
weight.conv1Weight = conv1Weight;
weight.conv1Bias = conv1Bias;
weight.conv4Weight = conv4Weight;
weight.conv4Bias = conv4Bias;
weight.linear8Weight = linear8Weight;
weight.linear8Bias = linear8Bias;
weight.linear10Weight = linear10Weight;
weight.linear10Bias = linear10Bias;