forked from sdemyanov/ConvNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetweights.m
More file actions
33 lines (31 loc) · 1007 Bytes
/
setweights.m
File metadata and controls
33 lines (31 loc) · 1007 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
function layers = setweights(layers, weights)
n = numel(layers);
ind = 0;
for l = 2 : n % layer
if strcmp(layers{l}.type, 'c') % convolutional
curlen = prod(layers{l}.kernelsize);
for i = 1 : layers{l}.outputmaps % output map
for j = 1 : layers{l-1}.outputmaps % input map
k_trans = layers{l}.k{i, j}';
k_trans(:) = weights(ind+1:ind+curlen);
layers{l}.k{i, j} = k_trans';
ind = ind + curlen;
end
end
curlen = layers{l}.outputmaps;
layers{l}.b(:) = weights(ind+1:ind+curlen);
ind = ind + curlen;
elseif strcmp(layers{l}.type, 'f') % fully connected
curlen = numel(layers{l}.w);
w_trans = layers{l}.w';
w_trans(:) = weights(ind+1:ind+curlen);
layers{l}.w = w_trans';
ind = ind + curlen;
curlen = length(layers{l}.b);
layers{l}.b(:) = weights(ind+1:ind+curlen);
ind = ind + curlen;
end;
end
%layers{end}.coef = weights(ind+1:ind+layers{end}.length);
%ind = ind + layers{end}.length;
end