-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoriginal.py
80 lines (71 loc) · 2.17 KB
/
original.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import os
from lib.common import train, predict
from lib.conf import SIZE, CLASS_NAMES, MODEL_DIR, SEPARATOR
import keras
def build_model(model_name: str):
if os.path.exists(f"{MODEL_DIR}/{model_name}.keras"):
return keras.models.load_model(f"{MODEL_DIR}/{model_name}.keras")
return keras.models.Sequential(
[
keras.layers.Input(shape=(SIZE, SIZE, 3)),
keras.layers.Conv2D(
16,
(3, 3),
activation=keras.activations.relu,
),
keras.layers.MaxPooling2D(2, 2),
keras.layers.Conv2D(
32,
(3, 3),
activation=keras.activations.relu,
),
keras.layers.MaxPooling2D(2, 2),
keras.layers.Conv2D(
64,
(3, 3),
activation=keras.activations.relu,
),
keras.layers.MaxPooling2D(2, 2),
keras.layers.Conv2D(
64,
(3, 3),
activation=keras.activations.relu,
),
keras.layers.MaxPooling2D(2, 2),
keras.layers.Conv2D(
64,
(3, 3),
activation=keras.activations.relu,
),
keras.layers.Conv2D(
64,
(3, 3),
activation=keras.activations.relu,
),
keras.layers.Flatten(),
keras.layers.Dense(
516,
activation=keras.activations.relu,
),
keras.layers.Dense(
256,
activation=keras.activations.relu,
),
keras.layers.Dense(
len(CLASS_NAMES), activation="softmax", name="classification"
),
],
name=model_name.replace("/", SEPARATOR),
)
class Original:
model = None
model_name = "original/fromzero"
def __init__(self):
self.model = build_model(self.model_name)
def summary(self):
self.model.summary()
print(self.model.name)
def train(self):
train(self.model)
def predict(self):
predict(self.model)