-
Notifications
You must be signed in to change notification settings - Fork 0
/
residualblockwithlayernames.py
390 lines (326 loc) · 23.2 KB
/
residualblockwithlayernames.py
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 20 14:18:24 2018
@author: ck807
"""
import keras
from keras import layers
import keras.backend as K
from keras.regularizers import l2
from Batch_Normalization import BatchNormalization
ROW_AXIS = 1
COL_AXIS = 2
CHANNEL_AXIS = 3
def initial_conv_block1(input, weight_decay=5e-4):
x = layers.Conv2D(32, (3, 3), padding='same', use_bias=False, kernel_initializer='he_normal',
kernel_regularizer=l2(weight_decay), name='conv1_1')(input)
x = BatchNormalization(axis=CHANNEL_AXIS, name='BN1_1', freeze=False)(x)
x = layers.LeakyReLU(name='Activation1_1')(x)
return x
def conv_block2(feat_maps_out, prev):
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN2_1', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation2_1')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv2_1')(prev)
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN2_2', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation2_2')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv2_2')(prev)
return prev
def skip_block2(feat_maps_in, feat_maps_out, prev):
if feat_maps_in != feat_maps_out:
# This adds in a 1x1 convolution on shortcuts that map between an uneven amount of channels
prev = layers.Conv2D(feat_maps_out, (1,1), padding = 'same', kernel_initializer = 'he_normal', name='Conv2_3')(prev)
return prev
def Residual2(feat_maps_in, feat_maps_out, prev_layer):
skip = skip_block2(feat_maps_in, feat_maps_out, prev_layer)
conv = conv_block2(feat_maps_out, prev_layer)
return keras.layers.Add(name='Add2_1')([skip, conv]) # the residual connection
def conv_block3(feat_maps_out, prev):
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN3_1', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation3_1')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv3_1')(prev)
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN3_2', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation3_2')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv3_2')(prev)
return prev
def skip_block3(feat_maps_in, feat_maps_out, prev):
if feat_maps_in != feat_maps_out:
# This adds in a 1x1 convolution on shortcuts that map between an uneven amount of channels
prev = layers.Conv2D(feat_maps_out, (1,1), padding = 'same', kernel_initializer = 'he_normal', name='Conv3_3')(prev)
return prev
def Residual3(feat_maps_in, feat_maps_out, prev_layer):
skip = skip_block3(feat_maps_in, feat_maps_out, prev_layer)
conv = conv_block3(feat_maps_out, prev_layer)
return keras.layers.Add(name='Add3_1')([skip, conv]) # the residual connection
def conv_block4(feat_maps_out, prev):
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN4_1', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation4_1')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv4_1')(prev)
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN4_2', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation4_2')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv4_2')(prev)
return prev
def skip_block4(feat_maps_in, feat_maps_out, prev):
if feat_maps_in != feat_maps_out:
# This adds in a 1x1 convolution on shortcuts that map between an uneven amount of channels
prev = layers.Conv2D(feat_maps_out, (1,1), padding = 'same', kernel_initializer = 'he_normal', name='Conv4_3')(prev)
return prev
def Residual4(feat_maps_in, feat_maps_out, prev_layer):
skip = skip_block4(feat_maps_in, feat_maps_out, prev_layer)
conv = conv_block4(feat_maps_out, prev_layer)
return keras.layers.Add(name='Add4_1')([skip, conv]) # the residual connection
def conv_block5(feat_maps_out, prev):
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN5_1', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation5_1')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv5_1')(prev)
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN5_2', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation5_2')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv5_2')(prev)
return prev
def skip_block5(feat_maps_in, feat_maps_out, prev):
if feat_maps_in != feat_maps_out:
# This adds in a 1x1 convolution on shortcuts that map between an uneven amount of channels
prev = layers.Conv2D(feat_maps_out, (1,1), padding = 'same', kernel_initializer = 'he_normal', name='Conv5_3')(prev)
return prev
def Residual5(feat_maps_in, feat_maps_out, prev_layer):
skip = skip_block5(feat_maps_in, feat_maps_out, prev_layer)
conv = conv_block5(feat_maps_out, prev_layer)
return keras.layers.Add(name='Add5_1')([skip, conv]) # the residual connection
def conv_block6(feat_maps_out, prev):
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN6_1', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation6_1')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv6_1')(prev)
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN6_2', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation6_2')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv6_2')(prev)
return prev
def skip_block6(feat_maps_in, feat_maps_out, prev):
if feat_maps_in != feat_maps_out:
# This adds in a 1x1 convolution on shortcuts that map between an uneven amount of channels
prev = layers.Conv2D(feat_maps_out, (1,1), padding = 'same', kernel_initializer = 'he_normal', name='Conv6_3')(prev)
return prev
def Residual6(feat_maps_in, feat_maps_out, prev_layer):
skip = skip_block6(feat_maps_in, feat_maps_out, prev_layer)
conv = conv_block6(feat_maps_out, prev_layer)
return keras.layers.Add(name='Add6_1')([skip, conv]) # the residual connection
def conv_block7(feat_maps_out, prev):
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN7_1', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation7_1')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv7_1')(prev)
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN7_2', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation7_2')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv7_2')(prev)
return prev
def skip_block7(feat_maps_in, feat_maps_out, prev):
if feat_maps_in != feat_maps_out:
# This adds in a 1x1 convolution on shortcuts that map between an uneven amount of channels
prev = layers.Conv2D(feat_maps_out, (1,1), padding = 'same', kernel_initializer = 'he_normal', name='Conv7_3')(prev)
return prev
def Residual7(feat_maps_in, feat_maps_out, prev_layer):
skip = skip_block7(feat_maps_in, feat_maps_out, prev_layer)
conv = conv_block7(feat_maps_out, prev_layer)
return keras.layers.Add(name='Add7_1')([skip, conv]) # the residual connection
def conv_block8(feat_maps_out, prev):
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN8_1', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation8_1')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv8_1')(prev)
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN8_2', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation8_2')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv8_2')(prev)
return prev
def skip_block8(feat_maps_in, feat_maps_out, prev):
if feat_maps_in != feat_maps_out:
# This adds in a 1x1 convolution on shortcuts that map between an uneven amount of channels
prev = layers.Conv2D(feat_maps_out, (1,1), padding = 'same', kernel_initializer = 'he_normal', name='Conv8_3')(prev)
return prev
def Residual8(feat_maps_in, feat_maps_out, prev_layer):
skip = skip_block8(feat_maps_in, feat_maps_out, prev_layer)
conv = conv_block8(feat_maps_out, prev_layer)
return keras.layers.Add(name='Add8_1')([skip, conv]) # the residual connection
def conv_block9(feat_maps_out, prev):
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN9_1', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation9_1')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv9_1')(prev)
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN9_2', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation9_2')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv9_2')(prev)
return prev
def skip_block9(feat_maps_in, feat_maps_out, prev):
if feat_maps_in != feat_maps_out:
# This adds in a 1x1 convolution on shortcuts that map between an uneven amount of channels
prev = layers.Conv2D(feat_maps_out, (1,1), padding = 'same', kernel_initializer = 'he_normal', name='Conv9_3')(prev)
return prev
def Residual9(feat_maps_in, feat_maps_out, prev_layer):
skip = skip_block9(feat_maps_in, feat_maps_out, prev_layer)
conv = conv_block9(feat_maps_out, prev_layer)
return keras.layers.Add(name='Add9_1')([skip, conv]) # the residual connection
def conv_block10(feat_maps_out, prev):
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN10_1', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation10_1')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv10_1')(prev)
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN10_2', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation10_2')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv10_2')(prev)
return prev
def skip_block10(feat_maps_in, feat_maps_out, prev):
if feat_maps_in != feat_maps_out:
# This adds in a 1x1 convolution on shortcuts that map between an uneven amount of channels
prev = layers.Conv2D(feat_maps_out, (1,1), padding = 'same', kernel_initializer = 'he_normal', name='Conv10_3')(prev)
return prev
def Residual10(feat_maps_in, feat_maps_out, prev_layer):
skip = skip_block10(feat_maps_in, feat_maps_out, prev_layer)
conv = conv_block10(feat_maps_out, prev_layer)
return keras.layers.Add(name='Add10_1')([skip, conv]) # the residual connection
def conv_block11(feat_maps_out, prev):
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN11_1', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation11_1')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv11_1')(prev)
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN11_2', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation11_2')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv11_2')(prev)
return prev
def skip_block11(feat_maps_in, feat_maps_out, prev):
if feat_maps_in != feat_maps_out:
# This adds in a 1x1 convolution on shortcuts that map between an uneven amount of channels
prev = layers.Conv2D(feat_maps_out, (1,1), padding = 'same', kernel_initializer = 'he_normal', name='Conv11_3')(prev)
return prev
def Residual11(feat_maps_in, feat_maps_out, prev_layer):
skip = skip_block11(feat_maps_in, feat_maps_out, prev_layer)
conv = conv_block11(feat_maps_out, prev_layer)
return keras.layers.Add(name='Add11_1')([skip, conv]) # the residual connection
def conv_block12(feat_maps_out, prev):
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN12_1', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation12_1')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv12_1')(prev)
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN12_2', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation12_2')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv12_2')(prev)
return prev
def skip_block12(feat_maps_in, feat_maps_out, prev):
if feat_maps_in != feat_maps_out:
# This adds in a 1x1 convolution on shortcuts that map between an uneven amount of channels
prev = layers.Conv2D(feat_maps_out, (1,1), padding = 'same', kernel_initializer = 'he_normal', name='Conv12_3')(prev)
return prev
def Residual12(feat_maps_in, feat_maps_out, prev_layer):
skip = skip_block12(feat_maps_in, feat_maps_out, prev_layer)
conv = conv_block12(feat_maps_out, prev_layer)
return keras.layers.Add(name='Add12_1')([skip, conv]) # the residual connection
def conv_block13(feat_maps_out, prev):
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN13_1', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation13_1')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv13_1')(prev)
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN13_2', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation13_2')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv13_2')(prev)
return prev
def skip_block13(feat_maps_in, feat_maps_out, prev):
if feat_maps_in != feat_maps_out:
# This adds in a 1x1 convolution on shortcuts that map between an uneven amount of channels
prev = layers.Conv2D(feat_maps_out, (1,1), padding = 'same', kernel_initializer = 'he_normal', name='Conv13_3')(prev)
return prev
def Residual13(feat_maps_in, feat_maps_out, prev_layer):
skip = skip_block13(feat_maps_in, feat_maps_out, prev_layer)
conv = conv_block13(feat_maps_out, prev_layer)
return keras.layers.Add(name='Add13_1')([skip, conv]) # the residual connection
def conv_block14(feat_maps_out, prev):
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN14_1', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation14_1')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv14_1')(prev)
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN14_2', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation14_2')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv14_2')(prev)
return prev
def skip_block14(feat_maps_in, feat_maps_out, prev):
if feat_maps_in != feat_maps_out:
# This adds in a 1x1 convolution on shortcuts that map between an uneven amount of channels
prev = layers.Conv2D(feat_maps_out, (1,1), padding = 'same', kernel_initializer = 'he_normal', name='Conv14_3')(prev)
return prev
def Residual14(feat_maps_in, feat_maps_out, prev_layer):
skip = skip_block14(feat_maps_in, feat_maps_out, prev_layer)
conv = conv_block14(feat_maps_out, prev_layer)
return keras.layers.Add(name='Add14_1')([skip, conv]) # the residual connection
def conv_block15(feat_maps_out, prev):
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN15_1', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation15_1')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv15_1')(prev)
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN15_2', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation15_2')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv15_2')(prev)
return prev
def skip_block15(feat_maps_in, feat_maps_out, prev):
if feat_maps_in != feat_maps_out:
# This adds in a 1x1 convolution on shortcuts that map between an uneven amount of channels
prev = layers.Conv2D(feat_maps_out, (1,1), padding = 'same', kernel_initializer = 'he_normal', name='Conv15_3')(prev)
return prev
def Residual15(feat_maps_in, feat_maps_out, prev_layer):
skip = skip_block15(feat_maps_in, feat_maps_out, prev_layer)
conv = conv_block15(feat_maps_out, prev_layer)
return keras.layers.Add(name='Add15_1')([skip, conv]) # the residual connection
def conv_block16(feat_maps_out, prev):
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN16_1', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation16_1')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv16_1')(prev)
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN16_2', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation16_2')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv16_2')(prev)
return prev
def skip_block16(feat_maps_in, feat_maps_out, prev):
if feat_maps_in != feat_maps_out:
# This adds in a 1x1 convolution on shortcuts that map between an uneven amount of channels
prev = layers.Conv2D(feat_maps_out, (1,1), padding = 'same', kernel_initializer = 'he_normal', name='Conv16_3')(prev)
return prev
def Residual16(feat_maps_in, feat_maps_out, prev_layer):
skip = skip_block16(feat_maps_in, feat_maps_out, prev_layer)
conv = conv_block16(feat_maps_out, prev_layer)
return keras.layers.Add(name='Add16_1')([skip, conv]) # the residual connection
def conv_block17(feat_maps_out, prev):
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN17_1', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation17_1')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv17_1')(prev)
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN17_2', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation17_2')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv17_2')(prev)
return prev
def skip_block17(feat_maps_in, feat_maps_out, prev):
if feat_maps_in != feat_maps_out:
# This adds in a 1x1 convolution on shortcuts that map between an uneven amount of channels
prev = layers.Conv2D(feat_maps_out, (1,1), padding = 'same', kernel_initializer = 'he_normal', name='Conv17_3')(prev)
return prev
def Residual17(feat_maps_in, feat_maps_out, prev_layer):
skip = skip_block17(feat_maps_in, feat_maps_out, prev_layer)
conv = conv_block17(feat_maps_out, prev_layer)
return keras.layers.Add(name='Add17_1')([skip, conv]) # the residual connection
def conv_block18(feat_maps_out, prev):
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN18_1', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation18_1')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv18_1')(prev)
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN18_2', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation18_2')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv18_2')(prev)
return prev
def skip_block18(feat_maps_in, feat_maps_out, prev):
if feat_maps_in != feat_maps_out:
# This adds in a 1x1 convolution on shortcuts that map between an uneven amount of channels
prev = layers.Conv2D(feat_maps_out, (1,1), padding = 'same', kernel_initializer = 'he_normal', name='Conv18_3')(prev)
return prev
def Residual18(feat_maps_in, feat_maps_out, prev_layer):
skip = skip_block18(feat_maps_in, feat_maps_out, prev_layer)
conv = conv_block18(feat_maps_out, prev_layer)
return keras.layers.Add(name='Add18_1')([skip, conv]) # the residual connection
def conv_block19(feat_maps_out, prev):
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN19_1', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation19_1')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv19_1')(prev)
prev = BatchNormalization(axis=CHANNEL_AXIS, name='BN19_2', freeze=False)(prev) # Specifying the axis and mode allows for later merging
prev = layers.LeakyReLU(name='Activation19_2')(prev)
prev = layers.Conv2D(feat_maps_out, (3,3), padding = 'same', kernel_initializer = 'he_normal', name='Conv19_2')(prev)
return prev
def skip_block19(feat_maps_in, feat_maps_out, prev):
if feat_maps_in != feat_maps_out:
# This adds in a 1x1 convolution on shortcuts that map between an uneven amount of channels
prev = layers.Conv2D(feat_maps_out, (1,1), padding = 'same', kernel_initializer = 'he_normal', name='Conv19_3')(prev)
return prev
def Residual19(feat_maps_in, feat_maps_out, prev_layer):
skip = skip_block19(feat_maps_in, feat_maps_out, prev_layer)
conv = conv_block19(feat_maps_out, prev_layer)
return keras.layers.Add(name='Add19_1')([skip, conv]) # the residual connection