-
Notifications
You must be signed in to change notification settings - Fork 72
/
build_model.py
executable file
·55 lines (43 loc) · 3.19 KB
/
build_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
from keras.models import Model
from keras.layers.merge import concatenate
from keras.layers import Input, Convolution2D, MaxPooling2D, UpSampling2D
def build_UNet2D_4L(inp_shape, k_size=3):
merge_axis = -1 # Feature maps are concatenated along last axis (for tf backend)
data = Input(shape=inp_shape)
conv1 = Convolution2D(filters=32, kernel_size=k_size, padding='same', activation='relu')(data)
conv1 = Convolution2D(filters=32, kernel_size=k_size, padding='same', activation='relu')(conv1)
pool1 = MaxPooling2D(pool_size=(2, 2))(conv1)
conv2 = Convolution2D(filters=64, kernel_size=k_size, padding='same', activation='relu')(pool1)
conv2 = Convolution2D(filters=64, kernel_size=k_size, padding='same', activation='relu')(conv2)
pool2 = MaxPooling2D(pool_size=(2, 2))(conv2)
conv3 = Convolution2D(filters=64, kernel_size=k_size, padding='same', activation='relu')(pool2)
conv3 = Convolution2D(filters=64, kernel_size=k_size, padding='same', activation='relu')(conv3)
pool3 = MaxPooling2D(pool_size=(2, 2))(conv3)
conv4 = Convolution2D(filters=128, kernel_size=k_size, padding='same', activation='relu')(pool3)
conv4 = Convolution2D(filters=128, kernel_size=k_size, padding='same', activation='relu')(conv4)
pool4 = MaxPooling2D(pool_size=(2, 2))(conv4)
conv5 = Convolution2D(filters=256, kernel_size=k_size, padding='same', activation='relu')(pool4)
up1 = UpSampling2D(size=(2, 2))(conv5)
conv6 = Convolution2D(filters=256, kernel_size=k_size, padding='same', activation='relu')(up1)
conv6 = Convolution2D(filters=256, kernel_size=k_size, padding='same', activation='relu')(conv6)
merged1 = concatenate([conv4, conv6], axis=merge_axis)
conv6 = Convolution2D(filters=256, kernel_size=k_size, padding='same', activation='relu')(merged1)
up2 = UpSampling2D(size=(2, 2))(conv6)
conv7 = Convolution2D(filters=256, kernel_size=k_size, padding='same', activation='relu')(up2)
conv7 = Convolution2D(filters=256, kernel_size=k_size, padding='same', activation='relu')(conv7)
merged2 = concatenate([conv3, conv7], axis=merge_axis)
conv7 = Convolution2D(filters=256, kernel_size=k_size, padding='same', activation='relu')(merged2)
up3 = UpSampling2D(size=(2, 2))(conv7)
conv8 = Convolution2D(filters=128, kernel_size=k_size, padding='same', activation='relu')(up3)
conv8 = Convolution2D(filters=128, kernel_size=k_size, padding='same', activation='relu')(conv8)
merged3 = concatenate([conv2, conv8], axis=merge_axis)
conv8 = Convolution2D(filters=128, kernel_size=k_size, padding='same', activation='relu')(merged3)
up4 = UpSampling2D(size=(2, 2))(conv8)
conv9 = Convolution2D(filters=64, kernel_size=k_size, padding='same', activation='relu')(up4)
conv9 = Convolution2D(filters=64, kernel_size=k_size, padding='same', activation='relu')(conv9)
merged4 = concatenate([conv1, conv9], axis=merge_axis)
conv9 = Convolution2D(filters=64, kernel_size=k_size, padding='same', activation='relu')(merged4)
conv10 = Convolution2D(filters=1, kernel_size=k_size, padding='same', activation='sigmoid')(conv9)
output = conv10
model = Model(data, output)
return model