Skip to content

Instantly share code, notes, and snippets.

@agnesmm agnesmm/a1g3.py Secret
Last active Sep 17, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.