-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmodels.py
executable file
·53 lines (40 loc) · 1.53 KB
/
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
47
48
49
50
51
52
53
from keras.layers.core import Dense
from keras.layers import LSTM, concatenate
from keras.models import Input, Model, Sequential
def build_block_model(lookback: int, inp_len: int) -> Sequential:
'''
Builds the block network model.
Args:
lookback (int): the lookback length
inp_len (int): length of the input
Returns:
keras.models.Sequential: the model
'''
model = Sequential()
model.add(LSTM(512, input_shape=(lookback, inp_len), return_sequences=True))
model.add(LSTM(512, return_sequences=True))
model.add(LSTM(400))
model.add(Dense(inp_len, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='rmsprop')
return model
def build_pos_model(lookback: int, inp_len: int) -> Sequential:
'''
Builds the position network model.
Args:
lookback (int): the lookback length
inp_len (int): length of the input
Returns:
keras.models.Sequential: the model
'''
inp = Input(shape=(lookback, inp_len))
x = LSTM(512, return_sequences=True)(inp)
x = LSTM(512, return_sequences=True)(x)
x = concatenate([x, inp])
x = LSTM(512, return_sequences=True)(x)
x = LSTM(256)(x)
pos = Dense(3, activation='linear', name='pos')(x)
rot = Dense(4, activation='softmax', name='rot')(x)
model = Model(inputs=inp, outputs=[pos, rot])
model.compile(loss=['mse', 'categorical_crossentropy'],
optimizer='rmsprop')
return model