Created
March 30, 2019 00:21
-
-
Save ResidentMario/52bb3b3fc03ff49e0521cae23475a899 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
model = Sequential() | |
model.add(Conv2D(64, kernel_size=(3, 3), input_shape=(96, 96, 3), activation='relu', padding='same')) | |
model.add(Conv2D(64, kernel_size=(3, 3), input_shape=(96, 96, 3), activation='relu', padding='same')) | |
model.add(MaxPooling2D(pool_size=(2, 2))) | |
# load the pretrained model | |
prior = load_model('resnet48_128/model-48.h5') | |
# add all but the first two layers of VGG16 to the new model | |
# strip the input layer out, this is now 96x96 | |
# also strip out the first convolutional layer, this took the 48x48 input and convolved it but | |
# this is now the job of the three new layers. | |
for layer in prior.layers[0].layers[2:]: | |
model.add(layer) | |
# re-add the feedforward layers on top | |
for layer in prior.layers[1:]: | |
model.add(layer) | |
# the pretrained CNN layers are already marked non-trainable | |
# mark off the top layers as well | |
for layer in prior.layers[-4:]: | |
layer.trainable = False | |
# compile the model | |
model.compile( | |
optimizer=RMSprop(), | |
loss='categorical_crossentropy', | |
metrics=['accuracy'] | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you please explain this piece of code