Skip to content

Instantly share code, notes, and snippets.

@agnesmm

agnesmm/a1g3.py Secret

Last active September 17, 2017 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agnesmm/4bfae1b8982c99f798acacdabfc2afda to your computer and use it in GitHub Desktop.
Save agnesmm/4bfae1b8982c99f798acacdabfc2afda to your computer and use it in GitHub Desktop.
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