-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdensenet_2d.m
More file actions
170 lines (146 loc) · 7.74 KB
/
Copy pathdensenet_2d.m
File metadata and controls
170 lines (146 loc) · 7.74 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
%% Create Layer Graph
% Create the layer graph variable to contain the network layers.
%define n as number of channels
n = 1;
lgraph = layerGraph();
%% Add Layer Branches
% Add the branches of the network to the layer graph. Each branch is a linear
% array of layers.
tempLayers = [
imageInputLayer([64 64 n],"Name","input","Normalization","none")
batchNormalizationLayer("Name","BN_Module1_Level1")
convolution2dLayer([3 3],32,"Name","conv_Module1_Level1","Padding","same","WeightsInitializer","narrow-normal")
reluLayer("Name","relu_Module1_Level1")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
batchNormalizationLayer("Name","BN_Module1_Level2")
convolution2dLayer([3 3],64,"Name","conv_Module1_Level2","Padding","same","WeightsInitializer","narrow-normal")
reluLayer("Name","relu_Module1_Level2")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = depthConcatenationLayer(2,"Name","depthcat_1");
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
maxPooling2dLayer([2 2],"Name","maxpool_Module1","Padding","same","Stride",[2 2])
batchNormalizationLayer("Name","BN_Module2_Level1")
convolution2dLayer([3 3],64,"Name","conv_Module2_Level1","Padding","same","WeightsInitializer","narrow-normal")
reluLayer("Name","relu_Module2_Level1")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
batchNormalizationLayer("Name","BN_Module2_Level2")
convolution2dLayer([3 3],128,"Name","conv_Module2_Level2","Padding","same","WeightsInitializer","narrow-normal")
reluLayer("Name","relu_Module2_Level2")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = depthConcatenationLayer(2,"Name","depthcat_2");
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
maxPooling2dLayer([2 2],"Name","maxpool_Module2","Padding","same","Stride",[2 2])
batchNormalizationLayer("Name","BN_Module3_Level1")
convolution2dLayer([3 3],128,"Name","conv_Module3_Level1","Padding","same","WeightsInitializer","narrow-normal")
reluLayer("Name","relu_Module3_Level1")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
batchNormalizationLayer("Name","BN_Module3_Level2")
convolution2dLayer([3 3],256,"Name","conv_Module3_Level2","Padding","same","WeightsInitializer","narrow-normal")
reluLayer("Name","relu_Module3_Level2")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = depthConcatenationLayer(2,"Name","depthcat_3");
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
maxPooling2dLayer([2 2],"Name","maxpool_Module3","Padding","same","Stride",[2 2])
batchNormalizationLayer("Name","BN_Module4_Level1")
convolution2dLayer([3 3],256,"Name","conv_Module4_Level1","Padding","same","WeightsInitializer","narrow-normal")
reluLayer("Name","relu_Module4_Level1")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
batchNormalizationLayer("Name","BN_Module4_Level2")
convolution2dLayer([3 3],512,"Name","conv_Module4_Level2","Padding","same","WeightsInitializer","narrow-normal")
reluLayer("Name","relu_Module4_Level2")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
depthConcatenationLayer(2,"Name","depthcat_5")
upsample2dLayer([2 2],512,"Name","upsample_Module4","Stride",[2 2])];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
depthConcatenationLayer(2,"Name","depthcat_4")
batchNormalizationLayer("Name","BN_Module5_Level1")
convolution2dLayer([3 3],256,"Name","conv_Module5_Level1","Padding","same","WeightsInitializer","narrow-normal")
reluLayer("Name","relu_Module5_Level1")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
batchNormalizationLayer("Name","BN_Module5_Level2")
convolution2dLayer([3 3],256,"Name","conv_Module5_Level2","Padding","same","WeightsInitializer","narrow-normal")
reluLayer("Name","relu_Module5_Level2")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
depthConcatenationLayer(2,"Name","depthcat_7")
upsample2dLayer([2 2],256,"Name","upsample_Module5","Stride",[2 2])];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
depthConcatenationLayer(2,"Name","depthcat_6")
batchNormalizationLayer("Name","BN_Module6_Level1")
convolution2dLayer([3 3],128,"Name","conv_Module6_Level1","Padding","same","WeightsInitializer","narrow-normal")
reluLayer("Name","relu_Module6_Level1")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
batchNormalizationLayer("Name","BN_Module6_Level2")
convolution2dLayer([3 3],128,"Name","conv_Module6_Level2","Padding","same","WeightsInitializer","narrow-normal")
reluLayer("Name","relu_Module6_Level2")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
depthConcatenationLayer(2,"Name","depthcat_8")
upsample2dLayer([2 2],128,"Name","upsample_Module6","Stride",[2 2])];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
depthConcatenationLayer(2,"Name","depthcat_9")
batchNormalizationLayer("Name","BN_Module7_Level1")
convolution2dLayer([3 3],64,"Name","conv_Module7_Level1","Padding","same")
reluLayer("Name","relu_Module7_Level1")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
batchNormalizationLayer("Name","BN_Module7_Level2")
convolution2dLayer([3 3],64,"Name","conv_Module7_Level2","Padding","same")
reluLayer("Name","relu_Module7_Level2")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
depthConcatenationLayer(2,"Name","depthcat_10")
batchNormalizationLayer("Name","BN_Module7_Level3")
convolution2dLayer([1 1],2,"Name","ConvLast_Module7")
softmaxLayer("Name","softmax")
dicePixelClassificationLayer("Name","output")];
lgraph = addLayers(lgraph,tempLayers);
% clean up helper variable
clear tempLayers;
%% Connect Layer Branches
% Connect all the branches of the network to create the network graph.
lgraph = connectLayers(lgraph,"relu_Module1_Level1","BN_Module1_Level2");
lgraph = connectLayers(lgraph,"relu_Module1_Level1","depthcat_1/in1");
lgraph = connectLayers(lgraph,"relu_Module1_Level2","depthcat_1/in2");
lgraph = connectLayers(lgraph,"depthcat_1","maxpool_Module1");
lgraph = connectLayers(lgraph,"depthcat_1","depthcat_9/in1");
lgraph = connectLayers(lgraph,"relu_Module2_Level1","BN_Module2_Level2");
lgraph = connectLayers(lgraph,"relu_Module2_Level1","depthcat_2/in1");
lgraph = connectLayers(lgraph,"relu_Module2_Level2","depthcat_2/in2");
lgraph = connectLayers(lgraph,"depthcat_2","maxpool_Module2");
lgraph = connectLayers(lgraph,"depthcat_2","depthcat_6/in2");
lgraph = connectLayers(lgraph,"relu_Module3_Level1","BN_Module3_Level2");
lgraph = connectLayers(lgraph,"relu_Module3_Level1","depthcat_3/in1");
lgraph = connectLayers(lgraph,"relu_Module3_Level2","depthcat_3/in2");
lgraph = connectLayers(lgraph,"depthcat_3","maxpool_Module3");
lgraph = connectLayers(lgraph,"depthcat_3","depthcat_4/in1");
lgraph = connectLayers(lgraph,"relu_Module4_Level1","BN_Module4_Level2");
lgraph = connectLayers(lgraph,"relu_Module4_Level1","depthcat_5/in2");
lgraph = connectLayers(lgraph,"relu_Module4_Level2","depthcat_5/in1");
lgraph = connectLayers(lgraph,"upsample_Module4","depthcat_4/in2");
lgraph = connectLayers(lgraph,"relu_Module5_Level1","BN_Module5_Level2");
lgraph = connectLayers(lgraph,"relu_Module5_Level1","depthcat_7/in1");
lgraph = connectLayers(lgraph,"relu_Module5_Level2","depthcat_7/in2");
lgraph = connectLayers(lgraph,"upsample_Module5","depthcat_6/in1");
lgraph = connectLayers(lgraph,"relu_Module6_Level1","BN_Module6_Level2");
lgraph = connectLayers(lgraph,"relu_Module6_Level1","depthcat_8/in1");
lgraph = connectLayers(lgraph,"relu_Module6_Level2","depthcat_8/in2");
lgraph = connectLayers(lgraph,"upsample_Module6","depthcat_9/in2");
lgraph = connectLayers(lgraph,"relu_Module7_Level1","BN_Module7_Level2");
lgraph = connectLayers(lgraph,"relu_Module7_Level1","depthcat_10/in1");
lgraph = connectLayers(lgraph,"relu_Module7_Level2","depthcat_10/in2");
%% Plot Layers
plot(lgraph);