Skip to content

Instantly share code, notes, and snippets.

@gutomcosta
Created August 20, 2017 15:26
Show Gist options
  • Save gutomcosta/05a249c9d130fdb041f382a0eaf0e2e6 to your computer and use it in GitHub Desktop.
Save gutomcosta/05a249c9d130fdb041f382a0eaf0e2e6 to your computer and use it in GitHub Desktop.
CNN using VGG19 architecture
### TODO: Define your architecture.
from keras.layers import Conv2D, MaxPooling2D, GlobalAveragePooling2D
from keras.layers import Dropout, Flatten, Dense
from keras.models import Sequential
vgg19_model = Sequential()
vgg19_model.add(GlobalAveragePooling2D(input_shape=train_vgg19.shape[1:]))
vgg19_model.add(Dense(512, activation='relu'))
vgg19_model.add(Dropout(0.5))
vgg19_model.add(Dense(512, activation='relu'))
vgg19_model.add(Dense(133, activation='softmax'))
vgg19_model.summary()
### TODO: Train the model.
checkpointer = ModelCheckpoint(filepath='saved_models/weights.best.VGG19.hdf5',
verbose=1, save_best_only=True)
vgg19_model.fit(train_vgg19, train_targets,
validation_data=(valid_vgg19, valid_targets),validation_split=0.2,
epochs=20, batch_size=120, callbacks=[checkpointer], verbose=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment