-
Notifications
You must be signed in to change notification settings - Fork 0
/
NetMaker.py
108 lines (91 loc) · 2.99 KB
/
NetMaker.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import os
from Hyperparameters import DEBUG
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
from tensorflow.keras.models import Model
from tensorflow.keras.layers import Conv2D, Flatten, Dense, BatchNormalization, Input, concatenate, Reshape, Add
from keras.regularizers import l2
class MultilayerPerceptron:
def __init__(self) -> None:
input_layer = Input(
shape=(3, 3, 2), name="input")
x = Flatten()(input_layer)
x = Dense(128, activation="relu", name="Dense0")(x)
x = Dense(64, activation="relu", name="Dense1")(x)
x = Dense(32, activation="relu", name="Dense2")(x)
x = Dense(16, activation="relu", name="Dense3")(x)
x = Dense(8, activation="relu", name="Dense4")(x)
output_layer = Dense(1, activation="tanh", name="eval")(x)
self.evaluation_model = Model(inputs=input_layer, outputs=output_layer)
losstype = "mse"
self.evaluation_model.compile(
optimizer="sgd",
loss=losstype,
metrics=[],
)
self.evaluation_model.summary()
def get_model(self) -> Model:
return self.evaluation_model
class ConvolutionalNeuralNetwork:
def __init__(self) -> None:
input_layer = Input(
shape=(3, 3, 2), name="input")
x = Conv2D(
filters=256,
kernel_size=3,
strides=1,
padding="same",
activation="relu",
name="Conv0",
input_shape=(3, 3, 2),
)(input_layer)
x = Conv2D(
filters=256,
kernel_size=3,
strides=1,
padding="same",
activation="relu",
name="Conv1",
)(x)
preconv = x
postconv = Conv2D(
filters=256,
kernel_size=3,
strides=1,
padding="same",
activation="relu",
name="Conv2",
)(preconv)
preconv = Add()([preconv, postconv])
postconv = Conv2D(
filters=256,
kernel_size=3,
strides=1,
padding="same",
activation="relu",
name="Conv3",
)(preconv)
preconv = Add()([preconv, postconv])
postconv = Conv2D(
filters=256,
kernel_size=3,
strides=1,
padding="same",
activation="relu",
name="Conv4",
)(preconv)
preconv = Add()([preconv, postconv])
x = preconv
x = Flatten()(x)
x = Dense(32, activation="relu", name="Dense0")(x)
output_layer = Dense(1, activation="tanh", name="eval")(x)
self.evaluation_model = Model(inputs=input_layer, outputs=output_layer)
losstype = "mse"
self.evaluation_model.compile(
optimizer="sgd",
loss=losstype,
metrics=[],
)
if DEBUG:
self.evaluation_model.summary()
def get_model(self) -> Model:
return self.evaluation_model