forked from Susuowy/aml_challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vgg16.py
38 lines (27 loc) · 969 Bytes
/
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
32
33
34
35
36
37
38
from utils import *
from keras.layers import Flatten, Dense
from tensorflow.keras.applications.vgg16 import VGG16
from keras.models import Model
def get_model():
vgg16 = VGG16(input_shape=[WIDTH, HEIGHT, 3], weights='imagenet', include_top=False)
# Freeze all all but 3 last layers
for layer in vgg16.layers:
layer.trainable = False
x = Flatten()(vgg16.output)
pred = Dense(NUM_CLASSES, activation='softmax')(x)
model = Model(inputs=vgg16.input, outputs=pred)
model.summary()
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['acc'])
return model
if __name__ == '__main__':
train_XY, validation_XY, test_X = get_data_from_memory()
vgg16 = get_model()
vgg16.fit(
train_XY,
batch_size=BATCH_SIZE,
validation_data=validation_XY,
epochs=6,
verbose=True,
callbacks=get_callbacks()
)
make_predictions_from_memory(vgg16, test_X)