Created
January 4, 2019 08:27
-
-
Save jonathanoheix/2d16f5a39443ed05b0ba1e04d90f569c 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
from keras.layers import Dense, Input, Dropout, GlobalAveragePooling2D, Flatten, Conv2D, BatchNormalization, Activation, MaxPooling2D | |
from keras.models import Model, Sequential | |
from keras.optimizers import Adam | |
# number of possible label values | |
nb_classes = 7 | |
# Initialising the CNN | |
model = Sequential() | |
# 1 - Convolution | |
model.add(Conv2D(64,(3,3), padding='same', input_shape=(48, 48,1))) | |
model.add(BatchNormalization()) | |
model.add(Activation('relu')) | |
model.add(MaxPooling2D(pool_size=(2, 2))) | |
model.add(Dropout(0.25)) | |
# 2nd Convolution layer | |
model.add(Conv2D(128,(5,5), padding='same')) | |
model.add(BatchNormalization()) | |
model.add(Activation('relu')) | |
model.add(MaxPooling2D(pool_size=(2, 2))) | |
model.add(Dropout(0.25)) | |
# 3rd Convolution layer | |
model.add(Conv2D(512,(3,3), padding='same')) | |
model.add(BatchNormalization()) | |
model.add(Activation('relu')) | |
model.add(MaxPooling2D(pool_size=(2, 2))) | |
model.add(Dropout(0.25)) | |
# 4th Convolution layer | |
model.add(Conv2D(512,(3,3), padding='same')) | |
model.add(BatchNormalization()) | |
model.add(Activation('relu')) | |
model.add(MaxPooling2D(pool_size=(2, 2))) | |
model.add(Dropout(0.25)) | |
# Flattening | |
model.add(Flatten()) | |
# Fully connected layer 1st layer | |
model.add(Dense(256)) | |
model.add(BatchNormalization()) | |
model.add(Activation('relu')) | |
model.add(Dropout(0.25)) | |
# Fully connected layer 2nd layer | |
model.add(Dense(512)) | |
model.add(BatchNormalization()) | |
model.add(Activation('relu')) | |
model.add(Dropout(0.25)) | |
model.add(Dense(nb_classes, activation='softmax')) | |
opt = Adam(lr=0.0001) | |
model.compile(optimizer=opt, loss='categorical_crossentropy', metrics=['accuracy']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment