-
Notifications
You must be signed in to change notification settings - Fork 0
/
UNet.py
116 lines (102 loc) · 3.63 KB
/
UNet.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
from keras.layers import Conv2D, concatenate, Conv2DTranspose, Input, MaxPooling2D, ReLU, BatchNormalization, Dense
from keras.optimizers import Adam
from keras.models import load_model
from keras.models import Model
def UNet():
input_img = Input(shape=(256, 256, 3))
# Encoder
c1 = Conv2D(32, (3, 3),padding='same')(input_img)
c1 = BatchNormalization()(c1)
c1 = ReLU()(c1)
c1 = Conv2D(32, (3, 3),padding='same')(c1)
c1 = BatchNormalization()(c1)
c1 = ReLU()(c1)
p1 = MaxPooling2D((2,2))(c1)
c2 = Conv2D(64, (3, 3),padding='same')(p1)
c2 = BatchNormalization()(c2)
c2 = ReLU()(c2)
c2 = Conv2D(64, (3, 3),padding='same')(c2)
c2 = BatchNormalization()(c2)
c2 = ReLU()(c2)
p2 = MaxPooling2D((2,2))(c2)
c3 = Conv2D(128, (3, 3),padding='same')(p2)
c3 = BatchNormalization()(c3)
c3 = ReLU()(c3)
c3 = Conv2D(128, (3, 3),padding='same')(c3)
c3 = BatchNormalization()(c3)
c3 = ReLU()(c3)
p3 = MaxPooling2D((2,2))(c3)
c4 = Conv2D(256, (3, 3),padding='same')(p3)
c4 = BatchNormalization()(c4)
c4 = ReLU()(c4)
c4 = Conv2D(256, (3, 3),padding='same')(c4)
c4 = BatchNormalization()(c4)
c4 = ReLU()(c4)
p4 = MaxPooling2D((2,2))(c4)
c5 = Conv2D(512, (3, 3),padding='same')(p4)
c5 = BatchNormalization()(c5)
c5 = ReLU()(c5)
c5 = Conv2D(512, (3, 3),padding='same')(c5)
c5 = BatchNormalization()(c5)
c5 = ReLU()(c5)
p5 = MaxPooling2D((2,2))(c5)
c6 = Conv2D(1024, (3, 3),padding='same')(p5)
c6 = BatchNormalization()(c6)
c6 = ReLU()(c6)
c6 = Conv2D(1024, (3, 3),padding='same')(c6)
c6 = BatchNormalization()(c6)
c6 = ReLU()(c6)
# Decoder
t1 = Conv2DTranspose(512, (3,3),strides=(2,2),padding='same')(c6)
t1 = concatenate([t1, c5])
t1 = BatchNormalization()(t1)
t1 = ReLU()(t1)
t1 = Conv2D(512, (3,3),padding='same')(t1)
t1 = BatchNormalization()(t1)
t1 = ReLU()(t1)
t1 = Conv2D(512, (3,3),padding='same')(t1)
t1 = BatchNormalization()(t1)
t1 = ReLU()(t1)
t2 = Conv2DTranspose(256, (3,3),strides=(2,2),padding='same')(t1)
t2 = concatenate([t2, c4])
t2 = BatchNormalization()(t2)
t2 = ReLU()(t2)
t2 = Conv2D(256, (3,3),padding='same')(t2)
t2 = BatchNormalization()(t2)
t2 = ReLU()(t2)
t2 = Conv2D(256, (3,3),padding='same')(t2)
t2 = BatchNormalization()(t2)
t2 = ReLU()(t2)
t3 = Conv2DTranspose(128, (3,3),strides=(2,2),padding='same')(t2)
t3 = concatenate([t3, c3])
t3 = BatchNormalization()(t3)
t3 = ReLU()(t3)
t3 = Conv2D(128, (3,3),padding='same')(t3)
t3 = BatchNormalization()(t3)
t3 = ReLU()(t3)
t3 = Conv2D(128, (3,3),padding='same')(t3)
t3 = BatchNormalization()(t3)
t3 = ReLU()(t3)
t4 = Conv2DTranspose(64, (3,3),strides=(2,2),padding='same')(t3)
t4 = concatenate([t4, c2])
t4 = BatchNormalization()(t4)
t4 = ReLU()(t4)
t4 = Conv2D(64, (3,3),padding='same')(t4)
t4 = BatchNormalization()(t4)
t4 = ReLU()(t4)
t4 = Conv2D(64, (3,3),padding='same')(t4)
t4 = BatchNormalization()(t4)
t4 = ReLU()(t4)
t5 = Conv2DTranspose(32, (3,3),strides=(2,2),padding='same')(t4)
t5 = concatenate([t5, c1])
t5 = BatchNormalization()(t5)
t5 = ReLU()(t5)
t5 = Conv2D(32, (3,3),padding='same')(t5)
t5 = BatchNormalization()(t5)
t5 = ReLU()(t5)
t5 = Conv2D(32, (3,3),padding='same')(t5)
t5 = BatchNormalization()(t5)
t5 = ReLU()(t5)
y = Conv2DTranspose(1, (1,1), activation='sigmoid')(t5)
model = Model(input_img, y)
model.summary()