-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels_file.py
32 lines (28 loc) · 1.14 KB
/
models_file.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
# -*- coding: utf-8 -*-
"""
Transfer learning based models
"""
from tensorflow.keras.applications import MobileNet
from tensorflow.keras import layers,Model,losses
from tensorflow.keras import optimizers
#------------------------------------------------------------------------------
def modelMobileNet(rows=128,cols=128+256,lr=1e-2):
base = MobileNet(include_top=False, input_shape=(rows,cols,3))
for layer in base.layers[:-3]:
layer.trainable = False
base.layers[2].trainable = True
x=layers.AvgPool2D(2,2)(base.layers[-1].output)
# flat1=layers.GlobalMaxPool2D()(base.layers[-3].output)
# x=BatchNormalization()(base.layers[-1].output)
x=layers.Flatten()(x)
x=layers.Dropout(0.5)(x)
#x= Dense(32, activation='relu')(x)
output = layers.Dense(1, activation='sigmoid')(x)
model = Model(inputs=base.inputs,outputs=output)
opt=optimizers.RMSprop(lr)
# opt=optimizers.Adam(lr)
model.compile(optimizer=opt,#Adam(lr=1e-2),
loss=losses.binary_crossentropy,# losses.huber,
metrics=['acc'])
model.summary()
return model