forked from layumi/2015_Face_Detection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
f24net_normB.m
45 lines (41 loc) · 1.56 KB
/
f24net_normB.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
function net = f24net()
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', 0) ;
net.layers{end+1} = struct('type', 'pool', ...
'method', 'max', ...
'pool', [3 3], ...
'stride', 2, ...
'pad', 0) ;
net.layers{end+1} = struct('type', 'relu') ;
net.layers{end+1} = struct('type', 'conv', ...
'weights', {{0.01*randn(9,9,64,128, 'single'), zeros(1, 128, 'single')}}, ...
'stride', 1, ...
'pad', 0) ;
net.layers{end+1} = struct('type', 'relu') ;
net.layers{end+1} = struct('type', 'custom', ...
'weights', {{0.01*randn(1,1,144,2, 'single'), zeros(1, 2, '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, 5) ;
net = insertBnorm(net, 8) ;
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)) ;