-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
43 lines (30 loc) · 1.24 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
43
from keras.models import Model
from keras.layers import Input, Conv2D, MaxPooling2D
from blocks import *
def residual_attention_unet(input_size=(256, 256, 1)):
#卷積 filter 設置
f = [16, 32, 64, 128]
inputs = Input(input_size)
#編碼
encode0 = inputs
encode1 = residual_block(encode0, f[0], strides=1)
pooling1 = MaxPooling2D((2, 2))(encode1)
encode2 = residual_block(pooling1, f[1], strides=1)
pooling2 = MaxPooling2D((2, 2))(encode2)
encode3 = residual_block(pooling2, f[2], strides=1)
pooling3 = MaxPooling2D((2, 2))(encode3)
#橋
b0 = residual_block(pooling3, f[3], strides=1)
#解碼
up1 = upsample_concat_block(b0, encode3)
attention1 = attention_gate(encode3, up1, f[2])
decode1 = residual_block(attention1, f[2])
up2 = upsample_concat_block(decode1, encode2)
attention2 = attention_gate(encode2, up2, f[1])
decode2 = residual_block(attention2, f[1])
up3 = upsample_concat_block(decode2, encode1)
attention3 = attention_gate(encode1, up3, f[0])
decode3 = residual_block(attention3, f[0])
outputs = Conv2D(1, (1, 1), padding="same", activation="sigmoid")(decode3)
model = Model(inputs=inputs, outputs=outputs)
return model