-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathclassifier_vgg19.py
31 lines (26 loc) · 1.19 KB
/
classifier_vgg19.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
from classifier_base import BaseClassifier
from keras.applications import *
from keras.layers import *
from keras.engine import *
from config import *
class VGG19Classifier(BaseClassifier):
def __init__(self, name='vgg19', lr=1e-3, batch_size=BATCH_SIZE, weights_mode='loss', optimizer=None):
BaseClassifier.__init__(self, name, IM_SIZE_224,
lr, batch_size, weights_mode, optimizer)
def create_model(self):
# weights = 'imagenet' if self.context['load_imagenet_weights'] else None
model_vgg19 = VGG19(include_top=False, weights=None,
input_shape=(self.im_size, self.im_size, 3), pooling='avg')
for layer in model_vgg19.layers:
layer.trainable = False
x = model_vgg19.output
x = Dense(4096, activation='relu', name='fc1')(x)
x = BatchNormalization()(x)
x = Dense(4096, activation='relu', name='fc2')(x)
x = BatchNormalization()(x)
x = Dense(CLASSES, activation='softmax')(x)
model = Model(inputs=model_vgg19.inputs, outputs=x)
return model
if __name__ == '__main__':
classifier = VGG19Classifier('vgg19_little')
classifier.train()