-
Notifications
You must be signed in to change notification settings - Fork 72
/
classifier_vgg16.py
31 lines (26 loc) · 1.19 KB
/
classifier_vgg16.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 VGG16Classifier(BaseClassifier):
def __init__(self, name='vgg16', 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_vgg16 = VGG16(include_top=False, weights=weights,
input_shape=(self.im_size, self.im_size, 3), pooling='avg')
for layer in model_vgg16.layers:
layer.trainable = False
x = model_vgg16.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_vgg16.inputs, outputs=x)
return model
if __name__ == '__main__':
classifier = VGG16Classifier('vgg16_little')
classifier.train()