-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathnets.py
executable file
·59 lines (46 loc) · 2.19 KB
/
nets.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
# Copyright (c) 2021 Project Bee4Exp.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
from keras.layers import Activation, Conv2D, MaxPooling2D, Input, BatchNormalization, UpSampling2D, Add
from keras.models import Model
def SegmentationModel(input_shape=(256, 256, 3), out_channels=1):
""" Creates segmentation CNN model.
Args:
input_shape:
Shape of input without batch dimension.
out_channels:
Number of output channels in prediction.
Returns:
Keras model.
"""
img_input = Input(shape=input_shape, dtype='float32')
conv1 = Conv2D(64, (3, 3), activation='linear', padding='same', use_bias=False, name='conv1')(img_input)
x = BatchNormalization(axis=3)(conv1)
x = Activation('relu')(x)
x = MaxPooling2D((2, 2), strides=(2, 2), name='pool1')(x)
conv2 = Conv2D(128, (3, 3), activation='linear', padding='same', use_bias=False, name='conv2')(x)
x = BatchNormalization(axis=3)(conv2)
x = Activation('relu')(x)
x = MaxPooling2D((2, 2), strides=(2, 2), name='pool2')(x)
conv3 = Conv2D(256, (3, 3), activation='linear', padding='same', use_bias=False, name='conv3')(x)
x = BatchNormalization(axis=3)(conv3)
x = Activation('relu')(x)
x = MaxPooling2D((2, 2), strides=(2, 2), name='pool3')(x)
x = Conv2D(512, (1, 1), activation='linear', padding='same', use_bias=False, name='fc-conv2')(x)
x = BatchNormalization(axis=3)(x)
x = Activation('relu')(x)
x = UpSampling2D(2, interpolation='nearest')(x)
x = Conv2D(256, (3, 3), activation='linear', padding='same', use_bias=False, name='conv3u')(x)
x = Add()([x, conv3])
x = BatchNormalization(axis=3)(x)
x = Activation('relu')(x)
x = UpSampling2D(2, interpolation='nearest')(x)
x = Conv2D(128, (3, 3), activation='linear', padding='same', use_bias=False, name='conv2u')(x)
x = Add()([x, conv2])
x = BatchNormalization(axis=3)(x)
x = Activation('relu')(x)
x = Conv2D(out_channels, (1, 1), activation='linear', padding='same', use_bias=True, name='detector')(x)
x = Activation('sigmoid')(x)
model = Model(inputs=img_input, outputs=x)
return model