-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
65 lines (46 loc) · 3.12 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from config import *
import segmentation_models as sm
import keras_unet_collection.models as kuc
def model_chg(model_name=model_nam,height=height,width=width,channels=channels,classes=num_classes):
if model_name=='attention_unet':
model = kuc.att_unet_2d((height, width, channels), filter_num=[64, 128, 256, 512, 1024], n_labels=classes)
# uncomment if you want to use mix precision
# x = model.layers[-2].output # fetch the last layer previous layer output
# output = Conv2D(num_classes, kernel_size = (1,1), name="out", activation = 'softmax',dtype="float32")(x) # create new last layer
# model = Model(inputs = model.input, outputs=output)
return model
elif model_name=='unet':
model = sm.Unet(backbone_name='efficientnetb0', input_shape=(height, width, channels),
classes = num_classes, activation='softmax',
encoder_weights=None, weights=None)
# uncomment if you want to use mix precision
# x = model.layers[-2].output # fetch the last layer previous layer output
# output = Conv2D(num_classes, kernel_size = (1,1), name="out", activation = 'softmax',dtype="float32")(x) # create new last layer
# model = Model(inputs = model.input, outputs=output)
return model
elif model_name=='vnet':
model = kuc.vnet_2d((height,width,channels), filter_num=[16, 32, 64, 128, 256],
n_labels=num_classes ,res_num_ini=1, res_num_max=3,
activation='PReLU', output_activation='Softmax',
batch_norm=True, pool=False, unpool=False, name='vnet')
# uncomment if you want to use mix precision
# x = model.layers[-2].output # fetch the last layer previous layer output
# output = Conv2D(config['num_classes'], kernel_size = (1,1), name="out", activation = 'softmax',dtype="float32")(x) # create new last layer
# model = Model(inputs = model.input, outputs=output)
return model
elif model_name=="link_net":
model = sm.Linknet(backbone_name='efficientnetb0', input_shape=(height, width, channels),
classes = num_classes, activation='softmax',
encoder_weights=None, weights=None)
# x = model.layers[-2].output # fetch the last layer previous layer output
# output = Conv2D(config['num_classes'], kernel_size = (1,1), name="out", activation = 'softmax',dtype="float32")(x) # create new last layer
# model = Model(inputs = model.input, outputs=output)
return model
elif model_name=="pspnet":
model = sm.PSPNet(backbone_name='efficientnetb0', input_shape=(height, width, channels),
classes =num_classes, activation='softmax',
encoder_weights=None, weights=None)
# x = model.layers[-2].output # fetch the last layer previous layer output
# output = Conv2D(config['num_classes'], kernel_size = (1,1), name="out", activation = 'softmax',dtype="float32")(x) # create new last layer
# model = Model(inputs = model.input, outputs=output)
return model