-
Notifications
You must be signed in to change notification settings - Fork 2
/
MODEL.py
538 lines (456 loc) · 24.4 KB
/
MODEL.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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
from __future__ import division
# noinspection PyUnresolvedReferences
from tensorflow import keras
from tensorflow.keras.layers import Flatten,BatchNormalization
from tensorflow.keras.layers import Conv2D
from tensorflow.keras.layers import add
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Input, ZeroPadding2D, concatenate
from tensorflow.keras.layers import Dense, Dropout, Activation
from tensorflow.keras.layers import Convolution2D
from tensorflow.keras.layers import AveragePooling2D, GlobalAveragePooling2D, MaxPooling2D
from tensorflow.keras.layers import BatchNormalization
import six
from tensorflow.keras.regularizers import l2
from tensorflow.keras.models import Model
from tensorflow.keras import backend as K
K.set_image_data_format('channels_last')
try:
from tensorflow.keras import initializations
except ImportError:
from tensorflow.keras import initializers as initializations
import tensorflow.keras.backend as K
"""
author:tslgithub
email:[email protected]
time:2018-12-12
msg: You can choose the following model to train your image, and just switch in config.py:
VGG16,VGG19,InceptionV3,Xception,MobileNet,AlexNet,LeNet,ZF_Net,ResNet18,ResNet34,ResNet50,ResNet101,ResNet152,DenseNet
"""
class MODEL(object):
def __init__(self,config):
self.config = config
def input_shape_define(self):
return (self.config.normal_size, self.config.normal_size, self.config.channles)
def covn_block(self,model,kenal_number,kenal_size,padding,activation):
model.add(Convolution2D(kenal_number,kenal_size,padding=padding,activation=activation))
return model
def max_pooling_type(self,model,kenal_size,strides):
model.add(MaxPooling2D(pool_size=kenal_size,strides=strides))
return model
def mnist_net(self):
model = Sequential()
input_shape = (self.config.normal_size, self.config.normal_size, self.config.channles)
model.add(Convolution2D(96,(3,3),input_shape=input_shape,padding='same',activation='relu',kernel_initializer='uniform'))
model.add(Convolution2D(128,(3,3),padding='same',activation='relu'))
model.add(Convolution2D(128,(1,1),padding='same',activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
model.add(Convolution2D(256,(3,3),padding='same',activation='relu'))
model.add(Convolution2D(256,(1,1),padding='same',activation='relu'))
model.add(MaxPooling2D(pool_size=(2,2),strides=(2,2)))
model.add(Convolution2D(512, (3, 3), padding='same', activation='relu'))
model.add(Convolution2D(512, (3, 3), padding='same', activation='relu'))
model.add(Convolution2D(256, (1, 1), padding='same', activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
model.add(Convolution2D(512, (3, 3), padding='same', activation='relu'))
model.add(Convolution2D(512, (3, 3), padding='same', activation='relu'))
model.add(Convolution2D(256, (1, 1), padding='same', activation='relu'))
# model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
model.add(Flatten())
# model.add(Dense(4096,activation='relu'))
model.add(Dense(1024,activation='relu'))
model.add(Dropout(0.5))
# model.add(Dense(2048, activation='relu'))
model.add(Dense(1024, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(self.config.classNumber,activation='softmax'))
return model
#VGG16
def TSL16(self):
model = Sequential()
input_shape = (self.config.normal_size, self.config.normal_size, self.config.channles)
model.add(Convolution2D(64,kernel_size=(3,3),input_shape=input_shape,padding='same',activation='relu'))
model.add(Convolution2D(64,kernel_size=(3,3),padding='same',activation='relu'))
model = self.max_pooling_type(model,kenal_size=(2,2),strides=(2,2))
for i in range(2):
model = self.covn_block(model, kenal_number=128, kenal_size=(3, 3), padding='same', activation='relu')
model = self.max_pooling_type(model,kenal_size = (2,2),strides=(2,2))
for i in range(3):
model = self.covn_block(model,kenal_number=128, kenal_size=(3,3), padding='same',activation='relu')
model = self.max_pooling_type(model,kenal_size=(2,2),strides=(2,2))
for i in range(3):
model = self.covn_block(model,kenal_number=512,kenal_size=(3,3),padding='same',activation='relu')
model = self.max_pooling_type(model,kenal_size=(2,2),strides=(2,2))
for i in range(3):
model = self.covn_block(model,kenal_number=512,kenal_size=(3,3),padding='same',activation='relu')
model.add(Flatten())
# model.add(Dense(4096,activation='relu'))
model.add(Dense(1024,activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(1024,activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(self.config.classNumber,activation='softmax'))
return model
# AlexNet
def AlexNet(self):
model = Sequential()
# input_shape = (64,64, self.config.channles)
input_shape = (self.config.normal_size, self.config.normal_size, self.config.channles)
model.add(Convolution2D(96, (11, 11), input_shape=input_shape,strides=(4, 4), padding='valid',activation='relu', kernel_initializer='uniform'))
model.add(MaxPooling2D(pool_size=(3, 3), strides=(2, 2)))#26*26
model.add(Convolution2D(256, (5, 5), strides=(1, 1), padding='same', activation='relu', kernel_initializer='uniform'))
model.add(MaxPooling2D(pool_size=(3, 3), strides=(2, 2)))
model.add(Convolution2D(384, (3, 3), strides=(1, 1), padding='same', activation='relu', kernel_initializer='uniform'))
model.add(Convolution2D(384, (3, 3), strides=(1, 1), padding='same', activation='relu', kernel_initializer='uniform'))
model.add(Convolution2D(256, (3, 3), strides=(1, 1), padding='same', activation='relu', kernel_initializer='uniform'))
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
model.add(Flatten())
# model.add(Dense(4096, activation='relu'))
model.add(Dense(1024, activation='relu'))
model.add(Dropout(0.5))
# model.add(Dense(4096, activation='relu'))
model.add(Dense(1024, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(self.config.classNumber, activation='softmax'))
# model.compile(loss="categorical_crossentropy", optimizer="adam", metrics=["accuracy"])
return model
def VGG16(self):
model = Sequential()
input_shape= (self.config.normal_size, self.config.normal_size, self.config.channles)
model.add(Convolution2D(64,(3,3),input_shape=input_shape,activation='relu',padding='same'))
model.add(Convolution2D(64,(3,3),activation='relu',padding='same'))
model.add(MaxPooling2D(pool_size=(2,2),strides=(2,2)))
model.add(Convolution2D(128,(3,3),activation='relu',padding='same'))
model.add(Convolution2D(128,(3,3),activation='relu',padding='same'))
model.add(MaxPooling2D(pool_size=(2,2),strides=(2,2)))
model.add(Convolution2D(256,(3,3),activation='relu',padding='same'))
model.add(Convolution2D(256,(3,3),activation='relu',padding='same'))
model.add(Convolution2D(256,(3,3),activation='relu',padding='same'))
model.add(MaxPooling2D(pool_size=(2,2),strides=(2,2)))
model.add(Convolution2D(512,(3,3),activation='relu',padding='same'))
model.add(Convolution2D(512,(3,3),activation='relu',padding='same'))
model.add(Convolution2D(512,(3,3),activation='relu',padding='same'))
model.add(MaxPooling2D(pool_size=(2,2),strides=(2,2)))
model.add(Convolution2D(512,(3,3),activation='relu',padding='same'))
model.add(Convolution2D(512,(3,3),activation='relu',padding='same'))
model.add(Convolution2D(512,(3,3),activation='relu',padding='same'))
model.add(MaxPooling2D(pool_size=(2,2),strides=(2,2)))
model.add(Flatten())
model.add(Dense(1024,activation='relu'))
model.add(Dense(1024,activation='relu'))
model.add(Dense(self.config.classNumber,activation='softmax'))
return model
def VGG19(self):
model = Sequential()
input_shape= (self.config.normal_size, self.config.normal_size, self.config.channles)
model.add(Convolution2D(64,(3,3),input_shape=input_shape,activation='relu',padding='same'))
model.add(Convolution2D(64,(3,3),activation='relu',padding='same'))
model.add(MaxPooling2D(pool_size=(2,2),strides=(2,2)))
model.add(Convolution2D(128,(3,3),activation='relu',padding='same'))
model.add(Convolution2D(128,(3,3),activation='relu',padding='same'))
model.add(MaxPooling2D(pool_size=(2,2),strides=(2,2)))
model.add(Convolution2D(256,(3,3),activation='relu',padding='same'))
model.add(Convolution2D(256,(3,3),activation='relu',padding='same'))
model.add(Convolution2D(256,(3,3),activation='relu',padding='same'))
model.add(Convolution2D(256,(3,3),activation='relu',padding='same'))
model.add(MaxPooling2D(pool_size=(2,2),strides=(2,2)))
model.add(Convolution2D(512,(3,3),activation='relu',padding='same'))
model.add(Convolution2D(512,(3,3),activation='relu',padding='same'))
model.add(Convolution2D(512,(3,3),activation='relu',padding='same'))
model.add(Convolution2D(512,(3,3),activation='relu',padding='same'))
model.add(MaxPooling2D(pool_size=(2,2),strides=(2,2)))
model.add(Convolution2D(512,(3,3),activation='relu',padding='same'))
model.add(Convolution2D(512,(3,3),activation='relu',padding='same'))
model.add(Convolution2D(512,(3,3),activation='relu',padding='same'))
model.add(Convolution2D(512,(3,3),activation='relu',padding='same'))
model.add(MaxPooling2D(pool_size=(2,2),strides=(2,2)))
model.add(Flatten())
model.add(Dense(1024,activation='relu'))
model.add(Dense(1024,activation='relu'))
model.add(Dense(self.config.classNumber,activation='softmax'))
return model
#LeNet
def LeNet(self):
# initialize the model
model = Sequential()
inputShape = (self.config.normal_size, self.config.normal_size, self.config.channles)
model.add(Conv2D(20, (5, 5), padding="same", input_shape=inputShape))
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
# second set of CONV => RELU => POOL layers
model.add(Conv2D(50, (5, 5), padding="same"))
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
# first (and only) set of FC => RELU layers
model.add(Flatten())
model.add(Dense(500))
model.add(Activation("relu"))
# softmax classifier
model.add(Dense(self.config.classNumber))
model.add(Activation("softmax"))
# model.compile(loss="categorical_crossentropy", optimizer="adam", metrics=["accuracy"])
# return the constructed network architecture
return model
#ZF_Net,8 layers
def ZF_Net(self):
model = Sequential()
model.add(
Conv2D(96, (7, 7), strides=(2, 2),
input_shape=(self.config.normal_size, self.config.normal_size,self.config.channles),
padding='valid',
activation='relu',
kernel_initializer='uniform'))
model.add(MaxPooling2D(pool_size=(3, 3), strides=(2, 2)))
model.add(Conv2D(256, (5, 5), strides=(2, 2), padding='same', activation='relu', kernel_initializer='uniform'))
model.add(MaxPooling2D(pool_size=(3, 3), strides=(2, 2)))
model.add(Conv2D(384, (3, 3), strides=(1, 1), padding='same', activation='relu', kernel_initializer='uniform'))
model.add(Conv2D(384, (3, 3), strides=(1, 1), padding='same', activation='relu', kernel_initializer='uniform'))
model.add(Conv2D(256, (3, 3), strides=(1, 1), padding='same', activation='relu', kernel_initializer='uniform'))
model.add(MaxPooling2D(pool_size=(3, 3), strides=(2, 2)))
model.add(Flatten())
model.add(Dense(4096, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(4096, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(self.config.classNumber, activation='softmax'))
# model.compile(loss="categorical_crossentropy", optimizer="adam", metrics=["accuracy"])
return model
#RESNET
class ResnetBuilder(object):
# @staticmethod
def build(self,config, block_fn, repetitions):
"""Builds a custom ResNet like architecture.
Args:
input_shape: The input shape in the form (nb_channels, nb_rows, nb_cols)
num_outputs: The number of outputs at final softmax layer
block_fn: The block function to use. This is either `basic_block` or `bottleneck`.
The original paper used basic_block for layers < 50
repetitions: Number of repetitions of various block units.
At each block unit, the number of filters are doubled and the input size is halved
Returns:
The keras `Model`.
"""
input_shape = (config.normal_size,config.normal_size,config.channles)
num_outputs = config.classNumber
self._handle_dim_ordering()
block_fn = self._get_block(block_fn)
input = Input(shape=input_shape)
conv1 = self._conv_bn_relu(filters=64, kernel_size=(7, 7), strides=(2, 2))(input)
pool1 = MaxPooling2D(pool_size=(3, 3), strides=(2, 2), padding="same")(conv1)
block = pool1
filters = 64
for i, r in enumerate(repetitions):
block = self._residual_block(block_fn, filters=filters, repetitions=r, is_first_layer=(i == 0))(block)
filters *= 2
# Last activation
block = self._bn_relu(block)
# Classifier block
block_shape = K.int_shape(block)
pool2 = AveragePooling2D(pool_size=(block_shape[ROW_AXIS], block_shape[COL_AXIS]),
strides=(1, 1))(block)
flatten1 = Flatten()(pool2)
dense = Dense(units=num_outputs,
activation="softmax")(flatten1)
model = Model(inputs=input, outputs=dense)
# model.compile(loss="categorical_crossentropy", optimizer="adam", metrics=["accuracy"])
return model
def build_myResNet(self,config, block_fn, repetitions_a, repetitions_b):
"""Builds a custom ResNet like architecture.
Args:
input_shape: The input shape in the form (nb_channels, nb_rows, nb_cols)
num_outputs: The number of outputs at final softmax layer
block_fn: The block function to use. This is either `basic_block` or `bottleneck`.
The original paper used basic_block for layers < 50
repetitions: Number of repetitions of various block units.
At each block unit, the number of filters are doubled and the input size is halved
Returns:
The keras `Model`.
"""
channeles=3
input_shape = (config.normal_size,config.normal_size,min([config.channles,channeles]))
num_outputs = config.classNumber
self._handle_dim_ordering()
block_fn = self._get_block(block_fn)
inputA = Input(shape=input_shape)
conv1_a = self._conv_bn_relu(filters=64, kernel_size=(7, 7), strides=(2, 2))(inputA)
pool1_a = MaxPooling2D(pool_size=(3, 3), strides=(2, 2), padding="same")(conv1_a)
block_a = pool1_a
filters = 64
for i, r in enumerate(repetitions_a):
block_a = self._residual_block(block_fn, filters=filters, repetitions=r, is_first_layer=(i == 0))(block_a)
filters *= 2
# Last activation
block_a = self._bn_relu(block_a)
# Classifier block
block_shape = K.int_shape(block_a)
pool2_a = AveragePooling2D(pool_size=(block_shape[ROW_AXIS], block_shape[COL_AXIS]),
strides=(1, 1))(block_a)
flatten1_a = Flatten()(pool2_a)
inputB = Input(shape=input_shape)
conv1_b = self._conv_bn_relu(filters=64, kernel_size=(3, 3), strides=(2, 2))(inputB)
pool1_b = MaxPooling2D(pool_size=(3, 3), strides=(2, 2), padding="same")(conv1_b)
block_b = pool1_b
filters = 64
for i, r in enumerate(repetitions_b):
block_b = self._residual_block(block_fn, filters=filters, repetitions=r, is_first_layer=(i == 0))(block_b)
filters *= 2
# Last activation
block_b = self._bn_relu(block_b)
# Classifier block
block_shape = K.int_shape(block_b)
pool2_b = AveragePooling2D(pool_size=(block_shape[ROW_AXIS], block_shape[COL_AXIS]),
strides=(1, 1))(block_b)
flatten1_b = Flatten()(pool2_b)
combined = concatenate([flatten1_a, flatten1_b])
dense = Dense(units=num_outputs,
activation="softmax")(combined)
model = Model(inputs=[inputA,inputB], outputs=dense)
# model.compile(loss="categorical_crossentropy", optimizer="adam", metrics=["accuracy"])
return model
# @staticmethod
def build_myresnet(self, params):
return self.build_myResNet(params, self.basic_block, [2, 2, 2, 2], [2, 2, 2, 2])
# @staticmethod
def build_resnet18(self,params):
return self.build(params, self.basic_block, [2, 2, 2, 2])
# @staticmethod
def build_resnet34(self,params):
return self.build(params, self.basic_block, [3, 4, 6, 3])
# @staticmethod
def build_resnet50(self,params):
return self.build(params, self.bottleneck, [3, 4, 6, 3])
# @staticmethod
def build_resnet101(self,params):
return self.build(params, self.bottleneck, [3, 4, 23, 3])
# @staticmethod
def build_resnet152(self,params):
return self.build(params, self.bottleneck, [3, 8, 36, 3])
def _bn_relu(self,input):
"""Helper to build a BN -> relu block
"""
norm = BatchNormalization(axis=CHANNEL_AXIS)(input)
return Activation("relu")(norm)
def _conv_bn_relu(self,**conv_params):
"""Helper to build a conv -> BN -> relu block
"""
filters = conv_params["filters"]
kernel_size = conv_params["kernel_size"]
strides = conv_params.setdefault("strides", (1, 1))
kernel_initializer = conv_params.setdefault("kernel_initializer", "he_normal")
padding = conv_params.setdefault("padding", "same")
kernel_regularizer = conv_params.setdefault("kernel_regularizer", l2(1.e-4))
def f(input):
conv = Conv2D(filters=filters, kernel_size=kernel_size,
strides=strides, padding=padding,
kernel_initializer=kernel_initializer,
kernel_regularizer=kernel_regularizer)(input)
return self._bn_relu(conv)
return f
def _bn_relu_conv(self,**conv_params):
"""Helper to build a BN -> relu -> conv block.
This is an improved scheme proposed in http://arxiv.org/pdf/1603.05027v2.pdf
"""
filters = conv_params["filters"]
kernel_size = conv_params["kernel_size"]
strides = conv_params.setdefault("strides", (1, 1))
kernel_initializer = conv_params.setdefault("kernel_initializer", "he_normal")
padding = conv_params.setdefault("padding", "same")
kernel_regularizer = conv_params.setdefault("kernel_regularizer", l2(1.e-4))
def f(input):
activation = self._bn_relu(input)
return Conv2D(filters=filters, kernel_size=kernel_size,
strides=strides, padding=padding,
kernel_initializer=kernel_initializer,
kernel_regularizer=kernel_regularizer)(activation)
return f
def _shortcut(self,input, residual):
"""Adds a shortcut between input and residual block and merges them with "sum"
"""
# Expand channles of shortcut to match residual.
# Stride appropriately to match residual (width, height)
# Should be int if network architecture is correctly configured.
input_shape = K.int_shape(input)
residual_shape = K.int_shape(residual)
stride_width = int(round(input_shape[ROW_AXIS] / residual_shape[ROW_AXIS]))
stride_height = int(round(input_shape[COL_AXIS] / residual_shape[COL_AXIS]))
equal_channels = input_shape[CHANNEL_AXIS] == residual_shape[CHANNEL_AXIS]
shortcut = input
# 1 X 1 conv if shape is different. Else identity.
if stride_width > 1 or stride_height > 1 or not equal_channels:
shortcut = Conv2D(filters=residual_shape[CHANNEL_AXIS],
kernel_size=(1, 1),
strides=(stride_width, stride_height),
padding="valid",
kernel_initializer="he_normal",
kernel_regularizer=l2(0.0001))(input)
return add([shortcut, residual])
def _residual_block(self,block_function, filters, repetitions, is_first_layer=False):
"""Builds a residual block with repeating bottleneck blocks.
"""
def f(input):
for i in range(repetitions):
init_strides = (1, 1)
if i == 0 and not is_first_layer:
init_strides = (2, 2)
input = block_function(filters=filters, init_strides=init_strides,
is_first_block_of_first_layer=(is_first_layer and i == 0))(input)
return input
return f
def basic_block(self,filters, init_strides=(1, 1), is_first_block_of_first_layer=False):
"""Basic 3 X 3 convolution blocks for use on resnets with layers <= 34.
Follows improved proposed scheme in http://arxiv.org/pdf/1603.05027v2.pdf
"""
def f(input):
if is_first_block_of_first_layer:
# don't repeat bn->relu since we just did bn->relu->maxpool
conv1 = Conv2D(filters=filters, kernel_size=(3, 3),
strides=init_strides,
padding="same",
kernel_initializer="he_normal",
kernel_regularizer=l2(1e-4))(input)
else:
conv1 = self._bn_relu_conv(filters=filters, kernel_size=(3, 3),
strides=init_strides)(input)
residual = self._bn_relu_conv(filters=filters, kernel_size=(3, 3))(conv1)
return self._shortcut(input, residual)
return f
def bottleneck(self,filters, init_strides=(1, 1), is_first_block_of_first_layer=False):
"""Bottleneck architecture for > 34 layer resnet.
Follows improved proposed scheme in http://arxiv.org/pdf/1603.05027v2.pdf
Returns:
A final conv layer of filters * 4
"""
def f(input):
if is_first_block_of_first_layer:
# don't repeat bn->relu since we just did bn->relu->maxpool
conv_1_1 = Conv2D(filters=filters, kernel_size=(1, 1),
strides=init_strides,
padding="same",
kernel_initializer="he_normal",
kernel_regularizer=l2(1e-4))(input)
else:
conv_1_1 = self._bn_relu_conv(filters=filters, kernel_size=(1, 1),
strides=init_strides)(input)
conv_3_3 = self._bn_relu_conv(filters=filters, kernel_size=(3, 3))(conv_1_1)
residual = self._bn_relu_conv(filters=filters * 4, kernel_size=(1, 1))(conv_3_3)
return self._shortcut(input, residual)
return f
def _handle_dim_ordering(self):
global ROW_AXIS
global COL_AXIS
global CHANNEL_AXIS
if K.image_data_format() == 'channels_last':
ROW_AXIS = 1
COL_AXIS = 2
CHANNEL_AXIS = 3
else:
CHANNEL_AXIS = 1
ROW_AXIS = 2
COL_AXIS = 3
def _get_block(self,identifier):
if isinstance(identifier, six.string_types):
res = globals().get(identifier)
if not res:
raise ValueError('Invalid {}'.format(identifier))
return res
return identifier