-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfcnInitializeResNetwork4s.m
66 lines (53 loc) · 1.97 KB
/
fcnInitializeResNetwork4s.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
function net = fcnInitializeResNetwork4s(net, varargin)
opts.rnn = false;
opts.nh = 512;
opts.nClass = 150;
opts.resLayer = 50;
opts.newLr = 1;
opts = vl_argparse(opts, varargin) ;
nh = opts.nh;
nClass = opts.nClass;
%% Remove the last layer
net.removeLayer('deconv8') ;
filters = single(bilinear_u(4, nClass, nClass)) ;
net.addLayer('deconv8', ...
dagnn.ConvTranspose(...
'size', size(filters), ...
'upsample', 2, ...
'crop', 1, ...
'numGroups', nClass, ...
'hasBias', false), ...
'sum_3_out', 'x11', 'deconvf_3') ;
f = net.getParamIndex('deconvf_3') ;
net.params(f).value = filters ;
net.params(f).learningRate = 1 ;
net.params(f).weightDecay = 1 ;
net.addLayer('sftmx_bdr1',dagnn.SoftMax(), 'x11','sftmx_bdr1');
net.addLayer('pred_bdr1', Prediction(),'sftmx_bdr1','pred_bdr1');
%% poolsize3
net.addLayer('pooling5_dbr1',dagnn.Pooling('poolSize', 3,'pad', 1, 'stride',1,...
'method','avg'),'pred_bdr1', 'pooling5_bdr1');
net.addLayer('minus_bdr1',dagnn.Minus(), {'pred_bdr1', 'pooling5_bdr1'}, 'minus_bdr1');
net.addLayer('bdr1', BondryDetiction('size', 25,'sigma',5,'value', 2), 'minus_bdr1','bdr1');
%% build skip network
skip_inputs = {'res2cx', 'res2bx', 'res2ax'};
[net, classifier_out] = skipNetwork(net, skip_inputs, 256, 256, ...
nClass, opts.newLr, 'skip2');
net.addLayer('sum4', dagnn.Sum(), classifier_out, 'x12') ;
% net.addLayer('sum4', dagnn.Sum(), ['x11',classifier_out], 'sum_4_out') ;
net.addLayer('bdr1_filter',multiply(),{'bdr1','x12'}, 'bdr1_filter');
net.addLayer('sum5', dagnn.Sum(), {'bdr1_filter', 'x11'}, 'sum_4_out') ;
%% Add deconvolution layers
filters = single(bilinear_u(4, nClass, nClass)) ;
net.addLayer('deconv4', ...
dagnn.ConvTranspose(...
'size', size(filters), ...
'upsample', 2, ...
'crop', 1, ...
'numGroups', nClass, ...
'hasBias', false), ...
'sum_4_out', 'prediction', 'deconvf') ;
f = net.getParamIndex('deconvf') ;
net.params(f).value = filters ;
net.params(f).learningRate = 1 ;
net.params(f).weightDecay = 1 ;