2 sys.path.append(
"/home/salonsom/cvn_tensorflow/networks")
4 from keras.applications.xception
import Xception
5 from keras.applications.vgg16
import VGG16
6 from keras.applications.vgg19
import VGG19
7 from keras.applications.resnet50
import ResNet50
8 from keras.applications.inception_v3
import InceptionV3
9 from keras.applications.inception_resnet_v2
import InceptionResNetV2
10 from keras.applications.mobilenet
import MobileNet
11 from keras.applications.densenet
import DenseNet121
12 from keras.applications.densenet
import DenseNet169
13 from keras.applications.densenet
import DenseNet201
14 import my_model, inception_v4, se_resnet, se_resnet_saul, se_inception_v3, se_inception_resnet_v2, se_resnext, resnet, resnext
15 from keras.layers
import GlobalAveragePooling2D, Dense, Dropout,Activation,Flatten
16 from keras.layers
import Input
17 from keras.models
import Model
25 def _xception(num_classes=13, input_shape=[500, 500, 3], transfer_learning=None):
27 print(
'Architecture: Xception...')
29 model = Xception(include_top=
True, input_shape=input_shape, weights=
None, classes=num_classes)
39 def _vgg16(num_classes=13, input_shape=[500, 500, 3], transfer_learning=None):
41 print(
'Architecture: VGG-16...')
43 model = VGG16(include_top=
True, input_shape=input_shape, weights=
None, classes=num_classes)
53 def _vgg19(num_classes=13, input_shape=[500, 500, 3], transfer_learning=None):
55 print(
'Architecture: VGG-19...')
57 model = VGG19(include_top=
True, input_shape=input_shape, weights=
None, classes=num_classes)
67 def _resnet18(num_classes=13, input_shape=[500, 500, 3], transfer_learning=None):
69 print(
'Architecture: ResNet-18...')
81 def _resnet34(num_classes=13, input_shape=[500, 500, 3], transfer_learning=None):
83 print(
'Architecture: ResNet-34...')
95 def _resnet50(num_classes=13, input_shape=[500, 500, 3], transfer_learning=None):
97 print(
'Architecture: ResNet-50...')
101 if None == transfer_learning:
103 model = ResNet50(include_top=
True, input_shape=input_shape, weights=
None, classes=num_classes)
109 pre_model = ResNet50(weights=
'imagenet', include_top=
False)
111 last_layer = pre_model.output
112 x = Flatten()(last_layer)
113 x = Dense(num_classes, activation=
'softmax', name=
'fc1000')(x)
115 model = Model(inputs=pre_model.input, outputs=x)
117 if transfer_learning ==
'finetuning':
118 for layer
in model.layers[:-4]:
119 layer.trainable =
False 129 def _resnet101(num_classes=13, input_shape=[500, 500, 3], transfer_learning=None):
131 print(
'Architecture: ResNet-101...')
143 def _resnet152(num_classes=13, input_shape=[500, 500, 3], transfer_learning=None):
145 print(
'Architecture: ResNet-152...')
157 def _inceptionv3(num_classes=13, input_shape=[500, 500, 3], transfer_learning=None):
159 print(
'Architecture: Inception-v3...')
161 model = InceptionV3(include_top=
True, input_shape=input_shape, weights=
None, classes=num_classes)
171 def _inceptionv4(num_classes=13, input_shape=[500, 500, 3], transfer_learning=None):
173 print(
'Architecture: Inception-v4...')
180 ##################### 181 # InceptionResNetV2 # 182 ##################### 187 print(
'Architecture: Inception-ResNet-v2...')
189 model =
InceptionResNetV2(include_top=
True, input_shape=input_shape, weights=
None, classes=num_classes)
199 def _resnext(num_classes=13, input_shape=[500, 500, 3], transfer_learning=None):
201 print(
'Architecture: ResNeXt...')
203 model =
resnext.ResNext(include_top=
True, input_shape=input_shape, weights=
None, classes=num_classes)
213 def _seresnet18(num_classes=13, input_shape=[500, 500, 3], transfer_learning=None):
215 print(
'Architecture: SE-ResNet-18...')
217 model =
se_resnet.SEResNet18(include_top=
True, input_shape=input_shape, weights=
None, classes=num_classes)
227 def _seresnet34(num_classes=13, input_shape=[500, 500, 3], transfer_learning=None):
229 print(
'Architecture: SE-ResNet-34...')
231 model =
se_resnet.SEResNet34(include_top=
True, input_shape=input_shape, weights=
None, classes=num_classes)
241 def _seresnet50(num_classes=13, input_shape=[500, 500, 3], transfer_learning=None):
243 print(
'Architecture: SE-ResNet-50...')
245 model =
se_resnet.SEResNet50(include_top=
True, input_shape=input_shape, weights=
None, classes=num_classes)
255 def _seresnet101(num_classes=13, input_shape=[500, 500, 3], transfer_learning=None):
257 print(
'Architecture: SE-ResNet-101...')
259 model =
se_resnet.SEResNet101(include_top=
True, input_shape=input_shape, weights=
None, classes=num_classes)
269 def _seresnet154(num_classes=13, input_shape=[500, 500, 3], transfer_learning=None):
271 print(
'Architecture: SE-ResNet-154...')
273 model =
se_resnet.SEResNet154(include_top=
True, input_shape=input_shape, weights=
None, classes=num_classes)
283 def _seresnetsaul(num_classes=13, input_shape=[500, 500, 1], transfer_learning=None):
285 print(
'Architecture: SE-ResNet-34-Saul...')
298 def _seinceptionv3(num_classes=13, input_shape=[500, 500, 3], transfer_learning=None):
300 print(
'Architecture: SE-Inception-v3...')
307 ####################### 308 # SEInceptionResNetV2 # 309 ####################### 314 print(
'Architecture: SE-Inception-ResNet-v2...')
326 def _seresnext(num_classes=13, input_shape=[500, 500, 3], transfer_learning=None):
328 print(
'Architecture: SE-ResNeXt...')
330 model =
se_resnext.SEResNext(include_top=
True, input_shape=input_shape, weights=
None, classes=num_classes)
340 def _mobilenet(num_classes=13, input_shape=[500, 500, 3], transfer_learning=None):
342 print(
'Architecture: MobileNet...')
344 model = MobileNet(include_top=
True, input_shape=input_shape, weights=
None, classes=num_classes)
354 def _densenet121(num_classes=13, input_shape=[500, 500, 3], transfer_learning=None):
356 print(
'Architecture: DenseNet-121...')
358 model = DenseNet121(include_top=
True, input_shape=input_shape, weights=
None, classes=num_classes)
368 def _densenet169(num_classes=13, input_shape=[500, 500, 3], transfer_learning=None):
370 print(
'Architecture: DenseNet-169...')
372 model = DenseNet169(include_top=
True, input_shape=input_shape, weights=
None, classes=num_classes)
382 def _densenet201(num_classes=13, input_shape=[500, 500, 3], transfer_learning=None):
384 print(
'Architecture: DenseNet-201...')
386 model = DenseNet201(include_top=
True, input_shape=input_shape, weights=
None, classes=num_classes)
396 def _mymodel(num_classes=13, input_shape=[500, 500, 3], transfer_learning=None):
398 print(
'Architecture: Custom model...')
411 def create_model(network='resnet50', num_classes=13, input_shape=[500, 500, 3], transfer_learning=None):
413 network = network.lower()
415 if network ==
'xception':
417 model =
_xception(num_classes=num_classes, input_shape=input_shape, transfer_learning=transfer_learning)
419 elif network ==
'vgg16':
421 model =
_vgg16(num_classes=num_classes, input_shape=input_shape, transfer_learning=transfer_learning)
423 elif network ==
'vgg19':
425 model =
_vgg19(num_classes=num_classes, input_shape=input_shape, transfer_learning=transfer_learning)
427 elif network ==
'resnet18':
429 model =
_resnet18(num_classes=num_classes, input_shape=input_shape, transfer_learning=transfer_learning)
431 elif network ==
'resnet34':
433 model =
_resnet34(num_classes=num_classes, input_shape=input_shape, transfer_learning=transfer_learning)
435 elif network ==
'resnet50':
437 model =
_resnet50(num_classes=num_classes, input_shape=input_shape, transfer_learning=transfer_learning)
439 elif network ==
'resnet101':
441 model =
_resnet101(num_classes=num_classes, input_shape=input_shape, transfer_learning=transfer_learning)
443 elif network ==
'resnet152':
445 model =
_resnet152(num_classes=num_classes, input_shape=input_shape, transfer_learning=transfer_learning)
447 elif network ==
'inceptionv3':
449 model =
_inceptionv3(num_classes=num_classes, input_shape=input_shape, transfer_learning=transfer_learning)
451 elif network ==
'inceptionv4':
453 model =
_inceptionv4(num_classes=num_classes, input_shape=input_shape, transfer_learning=transfer_learning)
455 elif network ==
'inceptionresnetv2':
457 model =
_inceptionresnetv2(num_classes=num_classes, input_shape=input_shape, transfer_learning=transfer_learning)
459 elif network ==
'resnext':
461 model =
_resnext(num_classes=num_classes, input_shape=input_shape, transfer_learning=transfer_learning)
463 elif network ==
'seresnet18':
465 model =
_seresnet18(num_classes=num_classes, input_shape=input_shape, transfer_learning=transfer_learning)
467 elif network ==
'seresnet34':
469 model =
_seresnet34(num_classes=num_classes, input_shape=input_shape, transfer_learning=transfer_learning)
471 elif network ==
'seresnet50':
473 model =
_seresnet50(num_classes=num_classes, input_shape=input_shape, transfer_learning=transfer_learning)
475 elif network ==
'seresnet101':
477 model =
_seresnet101(num_classes=num_classes, input_shape=input_shape, transfer_learning=transfer_learning)
479 elif network ==
'seresnet154':
481 model =
_seresnet154(num_classes=num_classes, input_shape=input_shape, transfer_learning=transfer_learning)
483 elif network ==
'seresnetsaul':
485 model =
_seresnetsaul(num_classes=num_classes, input_shape=input_shape, transfer_learning=transfer_learning)
487 elif network ==
'seinceptionv3':
489 model =
_seinceptionv3(num_classes=num_classes, input_shape=input_shape, transfer_learning=transfer_learning)
491 elif network ==
'seinceptionresnetv2':
493 model =
_seinceptionresnetv2(num_classes=num_classes, input_shape=input_shape, transfer_learning=transfer_learning)
495 elif network ==
'seresnext':
497 model =
_seresnext(num_classes=num_classes, input_shape=input_shape, transfer_learning=transfer_learning)
499 elif network ==
'mobilenet':
501 model =
_mobilenet(num_classes=num_classes, input_shape=input_shape, transfer_learning=transfer_learning)
503 elif network ==
'densenet121':
505 model =
_densenet121(num_classes=num_classes, input_shape=input_shape, transfer_learning=transfer_learning)
507 elif network ==
'densenet169':
509 model =
_densenet169(num_classes=num_classes, input_shape=input_shape, transfer_learning=transfer_learning)
511 elif network ==
'densenet201':
513 model =
_densenet201(num_classes=num_classes, input_shape=input_shape, transfer_learning=transfer_learning)
517 model =
_mymodel(num_classes=num_classes, input_shape=input_shape, transfer_learning=transfer_learning)
def _resnet50(num_classes=13, input_shape=[500, transfer_learning=None)
def _inceptionv3(num_classes=13, input_shape=[500, transfer_learning=None)
def _vgg16(num_classes=13, input_shape=[500, transfer_learning=None)
def _densenet201(num_classes=13, input_shape=[500, transfer_learning=None)
def _seresnet101(num_classes=13, input_shape=[500, transfer_learning=None)
def SEResNet18(input_shape=None, width=1, bottleneck=False, weight_decay=1e-4, include_top=True, weights=None, input_tensor=None, pooling=None, classes=1000)
def _resnet152(num_classes=13, input_shape=[500, transfer_learning=None)
def _seinceptionresnetv2(num_classes=13, input_shape=[500, transfer_learning=None)
def SEResNext(input_shape=None, depth=29, cardinality=8, width=64, weight_decay=5e-4, include_top=True, weights=None, input_tensor=None, pooling=None, classes=10)
def _inceptionv4(num_classes=13, input_shape=[500, transfer_learning=None)
def _mymodel(num_classes=13, input_shape=[500, transfer_learning=None)
def _seinceptionv3(num_classes=13, input_shape=[500, transfer_learning=None)
def _inceptionresnetv2(num_classes=13, input_shape=[500, transfer_learning=None)
def _seresnet18(num_classes=13, input_shape=[500, transfer_learning=None)
def SEResNet34(input_shape=None, width=1, bottleneck=False, weight_decay=1e-4, include_top=True, weights=None, input_tensor=None, pooling=None, classes=1000)
def _seresnet154(num_classes=13, input_shape=[500, transfer_learning=None)
def _xception(num_classes=13, input_shape=[500, transfer_learning=None)
def create_model(num_classes=1001, dropout_prob=0.2, weights=None, include_top=True, transfer_learning=None, input_shape=None)
def InceptionResNetV2(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)
def _seresnext(num_classes=13, input_shape=[500, transfer_learning=None)
def build_resnet_18(input_shape, num_outputs)
def SEResNet101(input_shape=None, width=1, bottleneck=True, weight_decay=1e-4, include_top=True, weights=None, input_tensor=None, pooling=None, classes=1000)
def _densenet121(num_classes=13, input_shape=[500, transfer_learning=None)
def SEResNet34(input_shape=None, width=1, bottleneck=False, weight_decay=1e-4, include_top=True, weights=None, input_tensor=None, pooling=None, classes=1000)
def _seresnetsaul(num_classes=13, input_shape=[500, transfer_learning=None)
def SEResNet50(input_shape=None, width=1, bottleneck=True, weight_decay=1e-4, include_top=True, weights=None, input_tensor=None, pooling=None, classes=1000)
def my_model(input_shape=[500, classes=3)
def build_resnet_152(input_shape, num_outputs)
def _resnet101(num_classes=13, input_shape=[500, transfer_learning=None)
def _densenet169(num_classes=13, input_shape=[500, transfer_learning=None)
def _mobilenet(num_classes=13, input_shape=[500, transfer_learning=None)
def create_model(network='resnet50', num_classes=13, input_shape=[500, transfer_learning=None)
def build_resnet_34(input_shape, num_outputs)
def SEInceptionResNetV2(include_top=True, weights=None, input_tensor=None, input_shape=None, pooling=None, classes=1000)
def _resnext(num_classes=13, input_shape=[500, transfer_learning=None)
def SEResNet154(input_shape=None, width=1, bottleneck=True, weight_decay=1e-4, include_top=True, weights=None, input_tensor=None, pooling=None, classes=1000)
def _seresnet34(num_classes=13, input_shape=[500, transfer_learning=None)
def _resnet34(num_classes=13, input_shape=[500, transfer_learning=None)
def SEInceptionV3(include_top=True, weights=None, input_tensor=None, input_shape=None, pooling=None, classes=1000)
def _seresnet50(num_classes=13, input_shape=[500, transfer_learning=None)
def _resnet18(num_classes=13, input_shape=[500, transfer_learning=None)
def ResNext(input_shape=None, depth=29, cardinality=8, width=64, weight_decay=5e-4, include_top=True, weights=None, input_tensor=None, pooling=None, classes=10)
def build_resnet_101(input_shape, num_outputs)
def _vgg19(num_classes=13, input_shape=[500, transfer_learning=None)