-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodel.py
44 lines (29 loc) · 1.22 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
#!/usr/bin/env python3
"""
(c) Research Group CAMMA, University of Strasbourg, IHU Strasbourg, France
Website: http://camma.u-strasbg.fr
"""
import tensorflow as tf
import os
def preprocess(image, shape=[64, 64]):
image = tf.cast(image, tf.float32)
image = tf.image.resize(image, shape)
image = tf.reshape(image, shape + [3])
image = tf.keras.applications.mobilenet_v2.preprocess_input(image)
return tf.expand_dims(image, 0)
def build_model(input_shape=[64, 64]):
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Input(input_shape +[3], dtype = tf.float32))
model.add(tf.keras.applications.MobileNetV2(
input_shape=input_shape+[3],
alpha=1.0,
include_top=False,
weights=None))
model.add(tf.keras.layers.Flatten())
model.add(tf.keras.layers.LayerNormalization())
model.add(tf.keras.layers.Dropout(0))
model.add(tf.keras.layers.Lambda(lambda x: tf.expand_dims(x, 0)))
model.add(tf.keras.layers.LSTM(units=640, return_sequences=True, stateful=True))
model.add(tf.keras.layers.LayerNormalization())
model.add(tf.keras.layers.Dense(1, activation='sigmoid'))
return model