keras conv2d batchnorm

Solutions on MaxInterview for keras conv2d batchnorm by the best coders in the world

showing results for - "keras conv2d batchnorm"
Charlie
08 Apr 2018
1# import BatchNormalization
2from keras.layers.normalization import BatchNormalization
3
4# instantiate model
5model = Sequential()
6
7# we can think of this chunk as the input layer
8model.add(Dense(64, input_dim=14, init='uniform'))
9model.add(BatchNormalization())
10model.add(Activation('tanh'))
11model.add(Dropout(0.5))
12
13# we can think of this chunk as the hidden layer    
14model.add(Dense(64, init='uniform'))
15model.add(BatchNormalization())
16model.add(Activation('tanh'))
17model.add(Dropout(0.5))
18
19# we can think of this chunk as the output layer
20model.add(Dense(2, init='uniform'))
21model.add(BatchNormalization())
22model.add(Activation('softmax'))
23
24# setting up the optimization of our weights 
25sgd = SGD(lr=0.1, decay=1e-6, momentum=0.9, nesterov=True)
26model.compile(loss='binary_crossentropy', optimizer=sgd)
27
28# running the fitting
29model.fit(X_train, y_train, nb_epoch=20, batch_size=16, show_accuracy=True, validation_split=0.2, verbose = 2)