Created
June 16, 2018 03:57
-
-
Save f-rumblefish/686ff44e138093ac6276c6fbef8d2bf2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from keras.models import Sequential | |
from keras.layers import Conv2D, MaxPooling2D, GlobalAveragePooling2D, Dense | |
from keras.callbacks import EarlyStopping | |
################################################################################ | |
# Build the model | |
################################################################################ | |
model = Sequential() | |
model.add(Conv2D(32, (3, 3), activation='relu', padding='same', input_shape=input_shape_img)) | |
model.add(MaxPooling2D(pool_size=(2, 2))) | |
model.add(Conv2D(32, (3, 3), activation='relu', padding='same')) | |
model.add(MaxPooling2D(pool_size=(2, 2))) | |
model.add(Conv2D(32, (3, 3), activation='relu', padding='same')) | |
model.add(MaxPooling2D(pool_size=(2, 2))) | |
model.add(Conv2D(32, (3, 3), activation='relu', padding='same')) | |
model.add(MaxPooling2D(pool_size=(2, 2))) | |
model.add(Conv2D(32, (3, 3), activation='relu', padding='same')) | |
model.add(MaxPooling2D(pool_size=(2, 2))) | |
model.add(GlobalAveragePooling2D()) | |
model.add(Dense(num_classes, activation='sigmoid')) | |
model.compile(loss='binary_crossentropy', | |
optimizer='adam', | |
metrics=['accuracy']) | |
model.summary() | |
################################################################################ | |
# Train the model | |
################################################################################ | |
early_stop = EarlyStopping(monitor='loss', patience=5, verbose=1) | |
history = model.fit(train_img, train_lbl, | |
batch_size=batch_size, | |
epochs=num_epochs, | |
verbose=1, | |
validation_split=0.1, | |
callbacks=[early_stop]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment