forked from vlfeat/matconvnet-fcn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fcnInitializeModel16s.m
68 lines (58 loc) · 2.09 KB
/
fcnInitializeModel16s.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 = fcnInitializeModel16s(net)
%FCNINITIALIZEMODEL16S Initialize the FCN-16S model from FCN-32
%% Remove the last layer
net.removeLayer('deconv32') ;
%% Add the first Deconv layer
filters = single(bilinear_u(4, 1, 21)) ;
net.addLayer('deconv2', ...
dagnn.ConvTranspose('size', size(filters), ...
'upsample', 2, ...
'crop', [1 1 1 1], ...
'hasBias', false), ...
'x38', 'x39', 'deconv1f') ;
f = net.getParamIndex('deconv1f') ;
net.params(f).value = filters ;
net.params(f).learningRate = 0 ;
net.params(f).weightDecay = 1 ;
%% Add skip layers on top of pool4
net.addLayer('skip4', ...
dagnn.Conv('size', [1 1 512 21], 'pad', 0), ...
'x24', 'x40', {'skip4f','skip4b'});
f = net.getParamIndex('skip4f') ;
net.params(f).value = zeros(1, 1, 512, 21, 'single') ;
net.params(f).learningRate = 0.1 ;
net.params(f).weightDecay = 1 ;
f = net.getParamIndex('skip4b') ;
net.params(f).value = zeros(1, 1, 21, 'single') ;
net.params(f).learningRate = 2 ;
net.params(f).weightDecay = 1 ;
%% Add the summation layer
net.addLayer('sum1', dagnn.Sum(), {'x39', 'x40'}, 'x41') ;
%% Add deconvolutional layer implementing bilinear interpolation
filters = single(bilinear_u(32, 21, 21)) ;
net.addLayer('deconv16', ...
dagnn.ConvTranspose('size', size(filters), ...
'upsample', 16, ...
'crop', 8, ...
'numGroups', 21, ...
'hasBias', false, ...
'opts', net.meta.cudnnOpts), ...
'x41', 'prediction', 'deconv16f') ;
f = net.getParamIndex('deconv16f') ;
net.params(f).value = filters ;
net.params(f).learningRate = 0 ;
net.params(f).weightDecay = 1 ;
% Make sure that 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