-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_models.py
46 lines (32 loc) · 1.51 KB
/
make_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
import glob
from datetime import datetime
from tensorflow.keras import layers
from tensorflow.keras import models
from tensorflow.keras import regularizers
def save_model(model: models.Model, name: str, timestamp=True):
timestamp = datetime.now().strftime("%y-%m-%d_%H_%M_%S")
model.save('log/models/model_' + timestamp + '_' + name)
def load_model(name: str) -> models.Model:
path = glob.glob('log/models/model*' + name)
return models.load_model(path[0])
def make_simple_cnn(input_shape=(640, 640, 3)) -> models.Model:
model = models.Sequential()
l2_regularizer = regularizers.l2(0.001)
model.add(layers.Conv2D(32, (3, 3), kernel_regularizer=l2_regularizer,
activation='relu', input_shape=input_shape))
model.add(layers.MaxPool2D())
model.add(layers.Conv2D(64, (3, 3), kernel_regularizer=l2_regularizer,
activation='relu'))
model.add(layers.MaxPool2D((2, 2)))
model.add(layers.Conv2D(128, (3, 3), kernel_regularizer=l2_regularizer,
activation='relu'))
model.add(layers.MaxPool2D((2, 2)))
model.add(layers.Conv2D(128, (3, 3), kernel_regularizer=l2_regularizer,
activation='relu'))
model.add(layers.MaxPool2D((2, 2)))
model.add(layers.Flatten())
model.add(layers.Dense(512, kernel_regularizer=l2_regularizer,
activation='relu'))
model.add(layers.Dropout(0.5))
model.add(layers.Dense(1, activation='sigmoid'))
return model