-
Notifications
You must be signed in to change notification settings - Fork 0
/
models_reg.py
119 lines (92 loc) · 3.35 KB
/
models_reg.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
109
110
111
112
113
114
115
116
117
118
119
import os, sys, glob
import numpy as np
from tensorflow.keras import layers, models, optimizers
from sklearn.model_selection import train_test_split
def reg1(xshape, optimizer):
def _conv(x):
y = layers.Conv1D( filters=20
, kernel_size=2
, padding='causal'
, activation='relu'
, dilation_rate=1)(x)
return y
x = layers.Input(shape=xshape)
y = _conv(x)
for rate in (2,4,8):
y = _conv(y)
y = layers.AveragePooling1D(50, padding='same')(y)
y = layers.Conv1D(20, 100, padding='same', activation='relu')(y)
y = layers.Conv1D(10, 100, padding='same', activation='relu')(y)
y = layers.AveragePooling1D(100, padding='same')(y)
# Last layer - for label
y = layers.Conv1D(10, 10, padding='same')(y)
y = layers.AveragePooling1D(10, padding='same')(y)
y = layers.Reshape((10, ))(y)
y = layers.Dense(2, activation='relu')(y)
y = layers.Dense(1)(y)
model = models.Model(x, y)
model.compile(optimizer, 'mae', metrics=['mse', 'mae'])
return model
def reg1_mse(xshape, optimizer):
def _conv(x):
y = layers.Conv1D( filters=20
, kernel_size=2
, padding='causal'
, activation='relu'
, dilation_rate=1)(x)
return y
x = layers.Input(shape=xshape)
y = _conv(x)
for rate in (2,4,8):
y = _conv(y)
y = layers.AveragePooling1D(50, padding='same')(y)
y = layers.Conv1D(20, 100, padding='same', activation='relu')(y)
y = layers.Conv1D(10, 100, padding='same', activation='relu')(y)
y = layers.AveragePooling1D(100, padding='same')(y)
# Last layer - for label
y = layers.Conv1D(10, 10, padding='same')(y)
y = layers.AveragePooling1D(10, padding='same')(y)
y = layers.Reshape((10, ))(y)
y = layers.Dense(2, activation='relu')(y)
y = layers.Dense(1)(y)
model = models.Model(x, y)
model.compile(optimizer, 'mse', metrics=['mse', 'mae'])
return model
def reg2(xshape, optimizer):
def _conv(x):
y = layers.Conv1D( filters=20
, kernel_size=2
, padding='causal'
, activation='relu'
, dilation_rate=1)(x)
return y
x = layers.Input(shape=xshape)
y = _conv(x)
for rate in (2,4,8):
y = _conv(y)
y = layers.AveragePooling1D(50, padding='same')(y)
y = layers.Conv1D(20, 100, padding='same', activation='relu')(y)
y = layers.Conv1D(10, 100, padding='same', activation='relu')(y)
y = layers.AveragePooling1D(100, padding='same')(y)
# Last layer - for label
y = layers.Conv1D(1, 10, padding='same')(y)
y = layers.AveragePooling1D(1, padding='same')(y)
y = layers.Reshape((1, ))(y)
model = models.Model(x, y)
model.compile(optimizer, 'mae', metrics=['mae', 'mse'])
return model
MODELS = {
'reg1': reg1,
'reg1_mse': reg1_mse,
'reg2': reg2,
}
def main():
dataDir = sys.argv[1]
model_name = sys.argv[2]
# load data
x_train, x_valid, _, y_train, y_valid, _ = load_data(dataDir)
# load and draw model
model = MODELS[model_name](x_train, 'adam')
model.summary()
if __name__=='__main__':
main()