forked from Nishant-Pall/DL-Prac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrnn_test.py
75 lines (50 loc) · 1.35 KB
/
rnn_test.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
from numpy.core.fromnumeric import shape
import tensorflow as tf
from tensorflow import keras
from keras.models import Model
from keras.layers import LSTM, GRU, Input
import numpy as np
T = 8
D = 2
M = 3
X = np.random.randn(1, T, D)
print(f'X : {X}')
def lstm1():
input_ = Input(shape=(T, D))
rnn = LSTM(M, return_state=True)
x = rnn(input_)
model = Model(inputs=input_, outputs=x)
o, h, c = model.predict(X)
print('LSTM 1')
print(f'o:{o}')
print(f'h:{h}')
print(f'c:{c}')
def lstm2():
input_ = Input(shape=(T, D))
rnn = LSTM(M, return_state=True, return_sequences=True)
x = rnn(input_)
model = Model(inputs=input_, outputs=x)
o, h, c = model.predict(X)
print('LSTM 2')
print(f'o:{o}')
print(f'h:{h}')
print(f'c:{c}')
def gru1():
input_ = Input(shape=(T, D))
rnn = GRU(M, return_state=True)
x = rnn(input_)
model = Model(inputs=input_, outputs=x)
o, h = model.predict(X)
print('GRU 1')
print(f'o:{o}')
print(f'h:{h}')
def gru2():
input_ = Input(shape=(T, D))
rnn = GRU(M, return_state=True, return_sequences=True)
x = rnn(input_)
model = Model(inputs=input_, outputs=x)
o, h = model.predict(X)
print('GRU 2')
print(f'o:{o}')
print(f'h:{h}')
lstm1()