-
-
Save agnesmm/4bfae1b8982c99f798acacdabfc2afda to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from keras.applications.vgg16 import VGG16 | |
from keras.layers import GlobalAveragePooling2D, Flatten, Dense, Input, Dropout | |
from keras.models import Model | |
from keras.optimizers import Adam | |
from keras import backend as K | |
# include_top=False to remove the last layer | |
initial_model = VGG16(weights="imagenet", include_top=False, input_tensor = Input(shape=(3,224,224))) | |
x = Flatten()(initial_model.output) | |
# we add a Dense layer | |
x = Dense(batches.nb_class, activation='softmax')(x) | |
# new model with "frozen" layers (except the last one) | |
model = Model(initial_model.input, x) | |
for layer in initial_model.layers: layer.trainable=False | |
model.compile(optimizer=Adam(lr=0.001), | |
loss='categorical_crossentropy', | |
metrics=['accuracy']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment