-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_build_model.py
60 lines (42 loc) · 1.68 KB
/
_build_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import os
from keras.api.models import Sequential, load_model
from keras.api.layers import Input, TimeDistributed, Conv2D, MaxPooling2D, Flatten, LSTM, Dropout, Dense, GlobalAveragePooling1D, BatchNormalization
from keras.api.optimizers import Adam
from src.utils.path_utils import find_project_directory
from src.training._load_dataset import BATCH_SIZE
def build_model():
project_dir = find_project_directory()
if os.path.exists(os.path.join(project_dir, 'models/model.keras')):
print('Model already exists. Loading model...')
model = load_model('models/model.keras')
else:
print('Model not found. Building model...')
model = Sequential([
Input(shape=(8, 8, 12),
batch_size=BATCH_SIZE, name='input'),
Conv2D(64, (3, 3), activation='relu', padding='same'),
BatchNormalization(),
MaxPooling2D((2, 2)),
Conv2D(128, (3, 3), activation='relu', padding='same'),
BatchNormalization(),
MaxPooling2D((2, 2)),
Conv2D(256, (3, 3), activation='relu', padding='same'),
BatchNormalization(),
MaxPooling2D((2, 2)),
Flatten(),
Dense(512, activation='relu'),
Dropout(0.5),
Dense(256, activation='relu'),
Dropout(0.5),
Dense(128, activation='relu'),
Dropout(0.5),
Dense(64, activation='relu'),
Dropout(0.5),
Dense(1, activation='linear', name='value'),
])
model.compile(
optimizer=Adam(),
loss='mean_squared_error',
metrics=['accuracy']
)
return model