Skip to content

Instantly share code, notes, and snippets.

@maltseasy
Last active December 15, 2018 22:30
Show Gist options
  • Save maltseasy/163b003b5ca8c617395370be6d228eba to your computer and use it in GitHub Desktop.
Save maltseasy/163b003b5ca8c617395370be6d228eba to your computer and use it in GitHub Desktop.
# Create a MobileNet model
mobile = keras.applications.mobilenet.MobileNet()
# Modify the model
# Choose the 6th layer from the last
x = mobile.layers[-6].output
# Add a dropout and dense layer for predictions
x = Dropout(0.25)(x)
predictions = Dense(7, activation='softmax')(x)
# Create a new model with the new outputs
model = Model(inputs=mobile.input, outputs=predictions)
# Prevent everything except the last 23 layers from being trained
for layer in model.layers[:-23]:
layer.trainable = False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment