-
Notifications
You must be signed in to change notification settings - Fork 1
/
cluster_classify_model.py
145 lines (123 loc) · 6.29 KB
/
cluster_classify_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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import h5py
from keras.models import Model
from keras.layers import Input, Activation, Concatenate
from keras.layers import Flatten, Dropout
from keras.layers import Convolution2D, MaxPooling2D
from keras.layers import AveragePooling2D
def cluster_classify_model(inputs=(64, 64, 2), summary = True, nb_classes = 1, nb_feature = 6):
"""
Arguments:
inputs -- shape of the input images (channel, cols, rows)
"""
input_img = Input(shape=inputs)
conv1 = Convolution2D(
96, (5, 5), activation='relu', kernel_initializer='glorot_uniform',
padding='same', name='conv1')(input_img)
maxpool1 = MaxPooling2D(
pool_size=(2, 2), strides=(2, 2), name='maxpool1')(conv1)
fire2_squeeze = Convolution2D(
16, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
padding='same', name='fire2_squeeze')(maxpool1)
fire2_expand1 = Convolution2D(
64, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
padding='same', name='fire2_expand1')(fire2_squeeze)
fire2_expand2 = Convolution2D(
64, (3, 3), activation='relu', kernel_initializer='glorot_uniform',
padding='same', name='fire2_expand2')(fire2_squeeze)
merge2 = Concatenate()([fire2_expand1, fire2_expand2])
fire3_squeeze = Convolution2D(
16, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
padding='same', name='fire3_squeeze')(merge2)
fire3_expand1 = Convolution2D(
64, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
padding='same', name='fire3_expand1')(fire3_squeeze)
fire3_expand2 = Convolution2D(
64, (3, 3), activation='relu', kernel_initializer='glorot_uniform',
padding='same', name='fire3_expand2')(fire3_squeeze)
merge3 = Concatenate()([fire3_expand1, fire3_expand2])
fire4_squeeze = Convolution2D(
32, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
padding='same', name='fire4_squeeze')(merge3)
fire4_expand1 = Convolution2D(
128, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
padding='same', name='fire4_expand1')(fire4_squeeze)
fire4_expand2 = Convolution2D(
128, (3, 3), activation='relu', kernel_initializer='glorot_uniform',
padding='same', name='fire4_expand2')(fire4_squeeze)
merge4 = Concatenate()([fire4_expand1, fire4_expand2])
maxpool4 = MaxPooling2D(
pool_size=(2, 2), strides=(2, 2), name='maxpool4')(merge4)
fire5_squeeze = Convolution2D(
32, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
padding='same', name='fire5_squeeze')(maxpool4)
fire5_expand1 = Convolution2D(
128, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
padding='same', name='fire5_expand1')(fire5_squeeze)
fire5_expand2 = Convolution2D(
128, (3, 3), activation='relu', kernel_initializer='glorot_uniform',
padding='same', name='fire5_expand2')(fire5_squeeze)
merge5 = Concatenate()([fire5_expand1, fire5_expand2])
fire6_squeeze = Convolution2D(
48, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
padding='same', name='fire6_squeeze')(merge5)
fire6_expand1 = Convolution2D(
192, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
padding='same', name='fire6_expand1')(fire6_squeeze)
fire6_expand2 = Convolution2D(
192, (3, 3), activation='relu', kernel_initializer='glorot_uniform',
padding='same', name='fire6_expand2')(fire6_squeeze)
merge6 = Concatenate()([fire6_expand1, fire6_expand2])
fire7_squeeze = Convolution2D(
48, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
padding='same', name='fire7_squeeze')(merge6)
fire7_expand1 = Convolution2D(
192, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
padding='same', name='fire7_expand1')(fire7_squeeze)
fire7_expand2 = Convolution2D(
192, (3, 3), activation='relu', kernel_initializer='glorot_uniform',
padding='same', name='fire7_expand2')(fire7_squeeze)
merge7 = Concatenate()([fire7_expand1, fire7_expand2])
fire8_squeeze = Convolution2D(
64, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
padding='same', name='fire8_squeeze')(merge7)
fire8_expand1 = Convolution2D(
256, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
padding='same', name='fire8_expand1')(fire8_squeeze)
fire8_expand2 = Convolution2D(
256, (3, 3), activation='relu', kernel_initializer='glorot_uniform',
padding='same', name='fire8_expand2')(fire8_squeeze)
merge8 = Concatenate()([fire8_expand1, fire8_expand2])
maxpool8 = MaxPooling2D(
pool_size=(2, 2), strides=(2, 2), name='maxpool8')(merge8)
fire9_squeeze = Convolution2D(
64, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
padding='same', name='fire9_squeeze')(maxpool8)
fire9_expand1 = Convolution2D(
256, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
padding='same', name='fire9_expand1')(fire9_squeeze)
fire9_expand2 = Convolution2D(
256, (3, 3), activation='relu', kernel_initializer='glorot_uniform',
padding='same', name='fire9_expand2')(fire9_squeeze)
merge9 = Concatenate()([fire9_expand1, fire9_expand2])
fire9_dropout = Dropout(0.5, name='fire9_dropout')(merge9)
conv10 = Convolution2D(
nb_classes, (1, 1), kernel_initializer='glorot_uniform',
padding='valid', name='conv10')(fire9_dropout)
# The size should match the output of conv10
avgpool10 = AveragePooling2D(
(8, 8), name='avgpool10')(conv10)
flatten10 = Flatten(name='flatten10')(avgpool10)
sigmoid = Activation("sigmoid", name='sigmoid')(flatten10)
conv11 = Convolution2D(
nb_feature, (1, 1), kernel_initializer='glorot_uniform',
padding='valid', name='conv11')(fire9_dropout)
avgpool11 = AveragePooling2D(
(8, 8), name='avgpool11')(conv11)
flatten = Flatten(name='flatten')(avgpool11)
out = Concatenate(name='concat_out')([sigmoid, flatten])
model = Model(inputs=input_img, outputs=out)
if summary:
model.summary()
return model
if __name__ == '__main__':
model = cluster_classify_model()