forked from vlfeat/matconvnet-fcn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fcnInitializeModel8s.m
68 lines (58 loc) · 2.09 KB
/
fcnInitializeModel8s.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
function net = fcnInitializeModel8s(net)
%FCNINITIALIZEMODEL8S Initialize the FCN-8S model from FCN-16S
%% Remove the last layer
net.removeLayer('deconv16') ;
%% Add the first deconv layer
filters = single(bilinear_u(4, 1, 21)) ;
net.addLayer('deconv2bis', ...
dagnn.ConvTranspose('size', size(filters), ...
'upsample', 2, ...
'crop', 1, ...
'hasBias', false), ...
'x41', 'x42', 'deconv2bisf') ;
f = net.getParamIndex('deconv2bisf') ;
net.params(f).value = filters ;
net.params(f).learningRate = 0 ;
net.params(f).weightDecay = 1 ;
%% Add a convolutional layer that take as input the pool3 layer
net.addLayer('skip3', ...
dagnn.Conv('size', [1 1 256 21]), ...
'x17', 'x43', {'skip3f','skip3b'});
f = net.getParamIndex('skip3f') ;
net.params(f).value = zeros(1, 1, 256, 21, 'single') ;
net.params(f).learningRate = 0.01 ;
net.params(f).weightDecay = 1 ;
f = net.getParamIndex('skip3b') ;
net.params(f).value = zeros(1, 1, 21, 'single') ;
net.params(f).learningRate = 2 ;
net.params(f).weightDecay = 1 ;
%% Add the sumwise layer
net.addLayer('sum2', dagnn.Sum(), {'x42', 'x43'}, 'x44') ;
%% Add deconvolutional layer implementing bilinear interpolation
filters = single(bilinear_u(16, 21, 21)) ;
net.addLayer('deconv8', ...
dagnn.ConvTranspose('size', size(filters), ...
'upsample', 8, ...
'crop', 4, ...
'numGroups', 21, ...
'hasBias', false, ...
'opts', net.meta.cudnnOpts), ...
'x44', 'prediction', 'deconv8f') ;
f = net.getParamIndex('deconv8f') ;
net.params(f).value = filters ;
net.params(f).learningRate = 0 ;
net.params(f).weightDecay = 1 ;
% Make the output of the bilinear interpolator is not discared for
% visualization purposes
net.vars(net.getVarIndex('prediction')).precious = 1 ;
% empirical test
if 0
figure(100) ; clf ;
n = numel(net.vars) ;
for i=1:n
vl_tightsubplot(n,i) ;
showRF(net, 'input', net.vars(i).name) ;
title(sprintf('%s', net.vars(i).name)) ;
drawnow ;
end
end