Skip to content

Commit a9a61f4

Browse files
committed
keras model
1 parent fee752e commit a9a61f4

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

keras_simple_model.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from keras.layers import Input, Dense, Activation, ZeroPadding2D, BatchNormalization, Flatten, Conv2D
2+
# Kept the unused imports for future reference
3+
from keras.layers import AveragePooling2D, MaxPooling2D, Dropout, GlobalMaxPooling2D, GlobalAveragePooling2D
4+
from keras.models import Model
5+
import keras.backend as K
6+
7+
K.set_image_data_format('channels_last')
8+
9+
10+
def cnn_model(input_shape, show_table=False):
11+
"""
12+
Implementation of the HappyModel.
13+
14+
Arguments:
15+
input_shape -- shape of the images of the dataset
16+
17+
Returns:
18+
model -- a Model() instance in Keras
19+
"""
20+
21+
X_input = Input(input_shape)
22+
X = ZeroPadding2D((3, 3))(X_input)
23+
24+
X = Conv2D(32, (7, 7), strides=(1, 1), name='conv0')(X)
25+
X = BatchNormalization(axis=3, name='bn0')(X)
26+
X = Activation('relu')(X)
27+
X = MaxPooling2D((2, 2), name='max_pool')(X)
28+
29+
X = Flatten()(X)
30+
X = Dense(1, activation='sigmoid', name='fc')(X)
31+
32+
model = Model(inputs=X_input, outputs=X, name='HappyModel')
33+
34+
if show_table:
35+
model.summary()
36+
37+
return model
38+
39+
40+
def show_model_graph(model_instance, file_name):
41+
plot_model(model_instance, to_file=file_name)
42+
SVG(model_to_dot(model_instance).create(prog='dot', format='svg'))

0 commit comments

Comments
 (0)