-
Notifications
You must be signed in to change notification settings - Fork 1
/
basic_models.py
executable file
·49 lines (40 loc) · 1.59 KB
/
basic_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
from keras.models import *
from keras.layers import *
import keras.backend as K
# from .config import IMAGE_ORDERING
IMAGE_ORDERING = 'channels_last'
def vanilla_encoder(input_height=224, input_width=224):
kernel = 3
filter_size = 64
pad = 1
pool_size = 2
if IMAGE_ORDERING == 'channels_first':
img_input = Input(shape=(3, input_height, input_width))
elif IMAGE_ORDERING == 'channels_last':
img_input = Input(shape=(input_height, input_width, 3))
x = img_input
levels = []
x = (ZeroPadding2D((pad, pad), data_format=IMAGE_ORDERING))(x)
x = (Conv2D(filter_size, (kernel, kernel),
data_format=IMAGE_ORDERING, padding='valid'))(x)
x = (BatchNormalization())(x)
x = (Activation('relu'))(x)
x = (MaxPooling2D((pool_size, pool_size), data_format=IMAGE_ORDERING))(x)
levels.append(x)
x = (ZeroPadding2D((pad, pad), data_format=IMAGE_ORDERING))(x)
x = (Conv2D(128, (kernel, kernel), data_format=IMAGE_ORDERING,
padding='valid'))(x)
x = (BatchNormalization())(x)
x = (Activation('relu'))(x)
x = (MaxPooling2D((pool_size, pool_size), data_format=IMAGE_ORDERING))(x)
levels.append(x)
for _ in range(3):
x = (ZeroPadding2D((pad, pad), data_format=IMAGE_ORDERING))(x)
x = (Conv2D(256, (kernel, kernel),
data_format=IMAGE_ORDERING, padding='valid'))(x)
x = (BatchNormalization())(x)
x = (Activation('relu'))(x)
x = (MaxPooling2D((pool_size, pool_size),
data_format=IMAGE_ORDERING))(x)
levels.append(x)
return img_input, levels