forked from yanzhuangzhuang123/MCNN_in_Keras
-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
42 lines (35 loc) · 1.73 KB
/
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
# -*- coding:utf-8 -*-
from keras.models import Model
from keras.layers import Conv2D, MaxPooling2D, Input, Concatenate
def MCNN(input_shape=None):
inputs = Input(shape=input_shape)
# column 1
column_1 = Conv2D(16, (9, 9), padding='same', activation='relu')(inputs)
column_1 = MaxPooling2D(2)(column_1)
column_1 = (column_1)
column_1 = Conv2D(32, (7, 7), padding='same', activation='relu')(column_1)
column_1 = MaxPooling2D(2)(column_1)
column_1 = Conv2D(16, (7, 7), padding='same', activation='relu')(column_1)
column_1 = Conv2D(8, (7, 7), padding='same', activation='relu')(column_1)
# column 2
column_2 = Conv2D(20, (7, 7), padding='same', activation='relu')(inputs)
column_2 = MaxPooling2D(2)(column_2)
column_2 = (column_2)
column_2 = Conv2D(40, (5, 5), padding='same', activation='relu')(column_2)
column_2 = MaxPooling2D(2)(column_2)
column_2 = Conv2D(20, (5, 5), padding='same', activation='relu')(column_2)
column_2 = Conv2D(10, (5, 5), padding='same', activation='relu')(column_2)
# column 3
column_3 = Conv2D(24, (5, 5), padding='same', activation='relu')(inputs)
column_3 = MaxPooling2D(2)(column_3)
column_3 = (column_3)
column_3 = Conv2D(48, (3, 3), padding='same', activation='relu')(column_3)
column_3 = MaxPooling2D(2)(column_3)
column_3 = Conv2D(24, (3, 3), padding='same', activation='relu')(column_3)
column_3 = Conv2D(12, (3, 3), padding='same', activation='relu')(column_3)
# merge feature map of 3 columns in last dimension
merges = Concatenate(axis=-1)([column_1, column_2, column_3])
# density map
density_map = Conv2D(1, (1, 1), padding='same')(merges)
model = Model(inputs=inputs, outputs=density_map)
return model