-
Notifications
You must be signed in to change notification settings - Fork 1
/
nn_model.py
82 lines (70 loc) · 2.93 KB
/
nn_model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import tensorflow as tf
import keras
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten, Lambda
from keras.layers import Conv2D, MaxPooling2D
from keras import losses, regularizers
from keras.layers.normalization import BatchNormalization
def base_model(img_height, img_width, img_channels):
'''The proposed model.
Input: img_height, img_width, img_channels'''
model = Sequential()
# Normalization
model.add(Lambda(lambda x: x/255.,
input_shape=(img_height, img_width, img_channels)))
# Cov layers
model.add(Conv2D(24, kernel_size=(3, 3), padding='same',
activation='elu',
kernel_initializer='he_normal',
name='re_conv1'))
model.add(BatchNormalization(name='re_bn1'))
model.add(MaxPooling2D(pool_size=(2, 2), name='re_maxpool1'))
model.add(Conv2D(32, kernel_size=(3, 3), padding='same',
activation='elu',
kernel_initializer='he_normal',
name='re_conv2'))
model.add(BatchNormalization(name='re_bn2'))
model.add(MaxPooling2D(pool_size=(2, 2), name='re_maxpool2'))
model.add(Conv2D(48, kernel_size=(3, 3), padding='same',
activation='elu',
kernel_initializer='he_normal',
name='re_conv3'))
model.add(BatchNormalization(name='re_bn3'))
model.add(MaxPooling2D(pool_size=(2, 2), name='re_maxpool3'))
model.add(Conv2D(64, kernel_size=(3, 3), padding='same',
activation='elu',
kernel_initializer='he_normal',
name='re_conv4'))
model.add(BatchNormalization(name='re_bn4'))
model.add(MaxPooling2D(pool_size=(2, 2), name='re_maxpool4'))
model.add(Conv2D(64, kernel_size=(3, 3), padding='same',
activation='elu',
kernel_initializer='he_normal',
name='re_conv5'))
model.add(BatchNormalization(name='re_bn5'))
model.add(MaxPooling2D(pool_size=(2, 2), name='re_maxpool5'))
# Fullyconnected layer
model.add(Flatten())
model.add(Dense(1164,
activation='elu',
kernel_initializer='he_normal',
name='re_den1'))
model.add(Dropout(0.2))
model.add(Dense(100,
activation='elu',
kernel_initializer='he_normal',
name='re_den2'))
model.add(Dropout(0.2))
model.add(Dense(50,
activation='elu',
kernel_initializer='he_normal',
name='re_den3'))
model.add(Dropout(0.5))
model.add(Dense(10,
activation='elu',
kernel_initializer='he_normal',
name='re_den4'))
model.add(Dropout(0.5))
model.add(Dense(1, kernel_initializer='he_normal'))
model.compile(loss='mse', optimizer="Adam")
return model