convolutional neural network grayscale image in keras

Solutions on MaxInterview for convolutional neural network grayscale image in keras by the best coders in the world

showing results for - "convolutional neural network grayscale image in keras"
Francoise
21 Nov 2017
1# Three steps to create a CNN
2# 1. Convolution
3# 2. Activation
4# 3. Pooling
5# Repeat Steps 1,2,3 for adding more hidden layers
6
7# 4. After that make a fully connected network
8# This fully connected network gives ability to the CNN
9# to classify the samples
10
11model = Sequential()
12
13model.add(Conv2D(32, (3, 3), input_shape=(28,28,1)))
14model.add(BatchNormalization(axis=-1))
15model.add(Activation('relu'))
16model.add(Conv2D(32, (3, 3)))
17model.add(BatchNormalization(axis=-1))
18model.add(Activation('relu'))
19model.add(MaxPooling2D(pool_size=(2,2)))
20
21model.add(Conv2D(64,(3, 3)))
22model.add(BatchNormalization(axis=-1))
23model.add(Activation('relu'))
24model.add(Conv2D(64, (3, 3)))
25model.add(BatchNormalization(axis=-1))
26model.add(Activation('relu'))
27model.add(MaxPooling2D(pool_size=(2,2)))
28
29model.add(Flatten())
30
31# Fully connected layer
32model.add(Dense(512))
33model.add(BatchNormalization())
34model.add(Activation('relu'))
35model.add(Dropout(0.2))
36model.add(Dense(10))
37
38model.add(Activation('softmax'))
39