-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
166 lines (145 loc) · 6.27 KB
/
models.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
"""
@author: nam157
"""
from typing import List
from tensorflow.keras.layers import (BatchNormalization, Conv2D, Input,
LeakyReLU, MaxPooling2D, UpSampling2D,
concatenate)
from tensorflow.keras.models import Model
def table_net(input_shape: List[int] = (512, 512, 3), num_classes: int = 1):
inputs = Input(shape=input_shape)
# 512
use_bias = False
down0a = Conv2D(16, (3, 3), padding="same", use_bias=use_bias)(inputs)
down0a = BatchNormalization()(down0a)
down0a = LeakyReLU(alpha=0.1)(down0a)
down0a = Conv2D(16, (3, 3), padding="same", use_bias=use_bias)(down0a)
down0a = BatchNormalization()(down0a)
down0a = LeakyReLU(alpha=0.1)(down0a)
down0a_pool = MaxPooling2D((2, 2), strides=(2, 2))(down0a)
# 256
down0 = Conv2D(32, (3, 3), padding="same", use_bias=use_bias)(down0a_pool)
down0 = BatchNormalization()(down0)
down0 = LeakyReLU(alpha=0.1)(down0)
down0 = Conv2D(32, (3, 3), padding="same", use_bias=use_bias)(down0)
down0 = BatchNormalization()(down0)
down0 = LeakyReLU(alpha=0.1)(down0)
down0_pool = MaxPooling2D((2, 2), strides=(2, 2))(down0)
# 128
down1 = Conv2D(64, (3, 3), padding="same", use_bias=use_bias)(down0_pool)
down1 = BatchNormalization()(down1)
down1 = LeakyReLU(alpha=0.1)(down1)
down1 = Conv2D(64, (3, 3), padding="same", use_bias=use_bias)(down1)
down1 = BatchNormalization()(down1)
down1 = LeakyReLU(alpha=0.1)(down1)
down1_pool = MaxPooling2D((2, 2), strides=(2, 2))(down1)
# 64
down2 = Conv2D(128, (3, 3), padding="same", use_bias=use_bias)(down1_pool)
down2 = BatchNormalization()(down2)
down2 = LeakyReLU(alpha=0.1)(down2)
down2 = Conv2D(128, (3, 3), padding="same", use_bias=use_bias)(down2)
down2 = BatchNormalization()(down2)
down2 = LeakyReLU(alpha=0.1)(down2)
down2_pool = MaxPooling2D((2, 2), strides=(2, 2))(down2)
# 32
down3 = Conv2D(256, (3, 3), padding="same", use_bias=use_bias)(down2_pool)
down3 = BatchNormalization()(down3)
down3 = LeakyReLU(alpha=0.1)(down3)
down3 = Conv2D(256, (3, 3), padding="same", use_bias=use_bias)(down3)
down3 = BatchNormalization()(down3)
down3 = LeakyReLU(alpha=0.1)(down3)
down3_pool = MaxPooling2D((2, 2), strides=(2, 2))(down3)
# 16
down4 = Conv2D(512, (3, 3), padding="same", use_bias=use_bias)(down3_pool)
down4 = BatchNormalization()(down4)
down4 = LeakyReLU(alpha=0.1)(down4)
down4 = Conv2D(512, (3, 3), padding="same", use_bias=use_bias)(down4)
down4 = BatchNormalization()(down4)
down4 = LeakyReLU(alpha=0.1)(down4)
down4_pool = MaxPooling2D((2, 2), strides=(2, 2))(down4)
# 8
center = Conv2D(1024, (3, 3), padding="same", use_bias=use_bias)(down4_pool)
center = BatchNormalization()(center)
center = LeakyReLU(alpha=0.1)(center)
center = Conv2D(1024, (3, 3), padding="same", use_bias=use_bias)(center)
center = BatchNormalization()(center)
center = LeakyReLU(alpha=0.1)(center)
# center
up4 = UpSampling2D((2, 2))(center)
up4 = concatenate([down4, up4], axis=3)
up4 = Conv2D(512, (3, 3), padding="same", use_bias=use_bias)(up4)
up4 = BatchNormalization()(up4)
up4 = LeakyReLU(alpha=0.1)(up4)
up4 = Conv2D(512, (3, 3), padding="same", use_bias=use_bias)(up4)
up4 = BatchNormalization()(up4)
up4 = LeakyReLU(alpha=0.1)(up4)
up4 = Conv2D(512, (3, 3), padding="same", use_bias=use_bias)(up4)
up4 = BatchNormalization()(up4)
up4 = LeakyReLU(alpha=0.1)(up4)
# 16
up3 = UpSampling2D((2, 2))(up4)
up3 = concatenate([down3, up3], axis=3)
up3 = Conv2D(256, (3, 3), padding="same", use_bias=use_bias)(up3)
up3 = BatchNormalization()(up3)
up3 = LeakyReLU(alpha=0.1)(up3)
up3 = Conv2D(256, (3, 3), padding="same", use_bias=use_bias)(up3)
up3 = BatchNormalization()(up3)
up3 = LeakyReLU(alpha=0.1)(up3)
up3 = Conv2D(256, (3, 3), padding="same", use_bias=use_bias)(up3)
up3 = BatchNormalization()(up3)
up3 = LeakyReLU(alpha=0.1)(up3)
# 32
up2 = UpSampling2D((2, 2))(up3)
up2 = concatenate([down2, up2], axis=3)
up2 = Conv2D(128, (3, 3), padding="same", use_bias=use_bias)(up2)
up2 = BatchNormalization()(up2)
up2 = LeakyReLU(alpha=0.1)(up2)
up2 = Conv2D(128, (3, 3), padding="same", use_bias=use_bias)(up2)
up2 = BatchNormalization()(up2)
up2 = LeakyReLU(alpha=0.1)(up2)
up2 = Conv2D(128, (3, 3), padding="same", use_bias=use_bias)(up2)
up2 = BatchNormalization()(up2)
up2 = LeakyReLU(alpha=0.1)(up2)
# 64
up1 = UpSampling2D((2, 2))(up2)
up1 = concatenate([down1, up1], axis=3)
up1 = Conv2D(64, (3, 3), padding="same", use_bias=use_bias)(up1)
up1 = BatchNormalization()(up1)
up1 = LeakyReLU(alpha=0.1)(up1)
up1 = Conv2D(64, (3, 3), padding="same", use_bias=use_bias)(up1)
up1 = BatchNormalization()(up1)
up1 = LeakyReLU(alpha=0.1)(up1)
up1 = Conv2D(64, (3, 3), padding="same", use_bias=use_bias)(up1)
up1 = BatchNormalization()(up1)
up1 = LeakyReLU(alpha=0.1)(up1)
# 128
up0 = UpSampling2D((2, 2))(up1)
up0 = concatenate([down0, up0], axis=3)
up0 = Conv2D(32, (3, 3), padding="same", use_bias=use_bias)(up0)
up0 = BatchNormalization()(up0)
up0 = LeakyReLU(alpha=0.1)(up0)
up0 = Conv2D(32, (3, 3), padding="same", use_bias=use_bias)(up0)
up0 = BatchNormalization()(up0)
up0 = LeakyReLU(alpha=0.1)(up0)
up0 = Conv2D(32, (3, 3), padding="same", use_bias=use_bias)(up0)
up0 = BatchNormalization()(up0)
up0 = LeakyReLU(alpha=0.1)(up0)
# 256
up0a = UpSampling2D((2, 2))(up0)
up0a = concatenate([down0a, up0a], axis=3)
up0a = Conv2D(16, (3, 3), padding="same", use_bias=use_bias)(up0a)
up0a = BatchNormalization()(up0a)
up0a = LeakyReLU(alpha=0.1)(up0a)
up0a = Conv2D(16, (3, 3), padding="same", use_bias=use_bias)(up0a)
up0a = BatchNormalization()(up0a)
up0a = LeakyReLU(alpha=0.1)(up0a)
up0a = Conv2D(16, (3, 3), padding="same", use_bias=use_bias)(up0a)
up0a = BatchNormalization()(up0a)
up0a = LeakyReLU(alpha=0.1)(up0a)
# 512
classify = Conv2D(num_classes, (1, 1), activation="sigmoid")(up0a)
model = Model(inputs=inputs, outputs=classify)
return model
if __name__ == "__main__":
model = table_net()
print(model.summary())