-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshort2_skipNetwork_Sigmoid.m
85 lines (67 loc) · 2.93 KB
/
short2_skipNetwork_Sigmoid.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
function [net, layer_outs, classifier_outs] = short2_skipNetwork_Sigmoid(net, layer_in, ...
nh0, nh, ~, newLr, layer_prefix, shared)
num_skips = numel(layer_in);
classifier_outs = cell(1, num_skips);
layer_outs = cell(1, num_skips);
for i = 1 : num_skips
conv_layer = sprintf('%s_conv_%d', layer_prefix, i);
sigmoid_layer = sprintf('%s_sigmoid_%d',layer_prefix, i);
relu_layer = sprintf('%s_relu_%d',layer_prefix, i);
bn_layer = sprintf('%s_bn_%d',layer_prefix, i);
conv_out = sprintf('%s_conv_out_%d', layer_prefix, i);
sigmoid_out = sprintf('%s_sigmoid_out_%d', layer_prefix, i);
relu_out = sprintf('%s_relu_out_%d', layer_prefix, i);
bn_out = sprintf('%s_bn_out_%d', layer_prefix, i);
if shared
conv_param_f = sprintf('%s_f_%d',layer_prefix, nh0);
conv_param_b = sprintf('%s_b_%d',layer_prefix, nh0);
conv_f = 1e-2*randn(1, 1, nh0, nh, 'single');
conv_b = zeros(1, 1, nh, 'single');
else
conv_param_f = sprintf('%s_f_%d', layer_prefix, i);
conv_param_b = sprintf('%s_b_%d', layer_prefix, i);
conv_f = 1e-2*randn(1, 1, nh0, nh, 'single');
conv_b = zeros(1, 1, nh, 'single');
end
conv_in = layer_in{i};
%% Batch Normalization
bn_param_f = sprintf('%s_bn_f_%d', layer_prefix, i);
bn_param_b = sprintf('%s_bn_b_%d', layer_prefix, i);
bn_param_m = sprintf('%s_bn_m_%d', layer_prefix, i);
net.addLayer(bn_layer, ...
dagnn.BatchNorm(), ...
conv_in, bn_out, {bn_param_f, bn_param_b, bn_param_m});
f = net.getParamIndex(bn_param_f) ;
net.params(f).value = ones(nh0, 1, 'single') ;
net.params(f).learningRate = 1 * newLr;
net.params(f).weightDecay = 1 ;
f = net.getParamIndex(bn_param_b) ;
net.params(f).value = zeros(nh0, 1, 'single') ;
net.params(f).learningRate = 1 * newLr;
net.params(f).weightDecay = 1 ;
f = net.getParamIndex(bn_param_m) ;
net.params(f).value = zeros(nh0, 2, 'single') ;
net.params(f).learningRate = 0 ;
net.params(f).weightDecay = 0 ;
%% ReLU
net.addLayer(relu_layer, ...
dagnn.ReLU(),...
bn_out, relu_out);
%% conv layer
net.addLayer(conv_layer, ...
dagnn.Conv('size', [1 1 nh0 nh], 'pad', 0), ...
relu_out, conv_out, {conv_param_f,conv_param_b});
f = net.getParamIndex(conv_param_f) ;
net.params(f).value = conv_f ;
net.params(f).learningRate = 1 * newLr;
net.params(f).weightDecay = 1 ;
f = net.getParamIndex(conv_param_b) ;
net.params(f).value = conv_b ;
net.params(f).learningRate = 2 * newLr;
net.params(f).weightDecay = 1 ;
% net.addLayer(sigmoid_layer,dagnn.mySigmoid('slope',10,'threshold',0),conv_out,sigmoid_out);
net.addLayer(sigmoid_layer,dagnn.Sigmoid(),conv_out,sigmoid_out);
%% add an output layer
classifier_outs{i} = sigmoid_out;
layer_outs{i} = conv_out;
end