Skip to content

Instantly share code, notes, and snippets.

Created March 20, 2017 17:49
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 anonymous/a53ea755963ee600f62318fde7ff0cf5 to your computer and use it in GitHub Desktop.
Save anonymous/a53ea755963ee600f62318fde7ff0cf5 to your computer and use it in GitHub Desktop.
from keras.applications.vgg16 import VGG16
from keras.layers.core import Dense
from keras.layers.convolutional import Convolution2D, MaxPooling2D, ZeroPadding2D
from keras.layers.pooling import GlobalAveragePooling2D
from keras.optimizers import SGD, RMSprop, Adam
# Roughly the code I had writted
base_model = VGG16(weights='imagenet')
for layer im base_model.layers:
layer.trainable = False
# Grab the second-to-last layer (to bypass the built-in predictions layer)
build_off = model.get_layer('fc2')
predictions = Dense(2, activation='softmax')(build_off.output)
model = Model(base_model.input, predictions)
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