-
-
Notifications
You must be signed in to change notification settings - Fork 68
/
f48net_c_2.m
54 lines (50 loc) · 2.01 KB
/
f48net_c_2.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
function net = f48net_c()
opts.useBnorm = true ;
net.layers = {} ;
net.layers{end+1} = struct('type', 'conv', ...
'weights', {{0.01*randn(5,5,3,64, 'single'), zeros(1, 64, 'single')}}, ...
'stride', 1, ...
'pad', 1) ;
net.layers{end+1} = struct('type', 'pool', ...
'method', 'max', ...
'pool', [3 3], ...
'stride', 2, ...
'pad', 0) ;
%net.layers{end+1} = struct('type', 'normalize', 'name', 'norm1', ...
% 'param', [9 1 0.0001/5 0.75]) ;
net.layers{end+1} = struct('type', 'conv', ...
'weights', {{0.05*randn(5,5,64,64, 'single'), zeros(1, 64, 'single')}}, ...
'stride', 1, ...
'pad', 0) ;
%net.layers{end+1} = struct('type', 'normalize', 'name', 'norm1', ...
% 'param', [9 1 0.0001/5 0.75]) ;
net.layers{end+1} = struct('type', 'relu') ;
net.layers{end+1} = struct('type', 'conv', ...
'weights', {{0.05*randn(18,18,64,256, 'single'), zeros(1, 256, 'single')}}, ...
'stride', 1, ...
'pad', 0) ;
net.layers{end+1} = struct('type', 'relu') ;
net.layers{end+1} = struct('type', 'dropout', 'rate', 0.5) ;
net.layers{end+1} = struct('type', 'conv', ...
'weights', {{0.05*randn(1,1,256,45, 'single'), zeros(1, 45, 'single')}}, ...
'stride', 1, ...
'pad', 0) ;
net.layers{end+1} = struct('type', 'relu') ;
net.layers{end+1} = struct('type', 'softmaxloss') ;
% optionally switch to batch normalization
if opts.useBnorm
net = insertBnorm(net, 1) ;
net = insertBnorm(net, 4) ;
net = insertBnorm(net, 7) ;
end
% --------------------------------------------------------------------
function net = insertBnorm(net, l)
% --------------------------------------------------------------------
assert(isfield(net.layers{l}, 'weights'));
ndim = size(net.layers{l}.weights{1}, 4);
layer = struct('type', 'bnorm', ...
'weights', {{ones(ndim, 1, 'single'), zeros(ndim, 1, 'single')}}, ...
'learningRate', [1 1], ...
'weightDecay', [0 0]) ;
net.layers{l}.biases = [] ;
net.layers = horzcat(net.layers(1:l), layer, net.layers(l+1:end)) ;