-
Notifications
You must be signed in to change notification settings - Fork 1
/
temporal_test.py
55 lines (39 loc) · 1.85 KB
/
temporal_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
import tensorflow as tf
"""
constant_inp = tf.constant([[[1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1.]]])
gu = GatedLinearUnit(filters=32, kernel_size=3)
output = gu(constant_inp)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
import pdb;pdb.set_trace()
a = sess.run(output)
"""
input_sequence = tf.get_variable(shape=[1, 3, 4], initializer=tf.ones_initializer(), name="source")
conv_out = tf.layers.Conv1D(kernel_size=3, filters=3, activation=None)(input_sequence)
sequence = tf.constant([[ [1., 1., 1., 1.],
[1., 1., 1., 1.],
[1., 1., 1., 1.],
[2., 2., 2., 2.],
[2., 1., 1., 1.],
[2., 1., 1., 1.]]])
def body(conv_out, input_sequence, sequence, i):
input_sequence = sequence[:,i:i+3,:]#.set_shape([1,3,4])
#subset.set_shape([1, 3,4])
return conv_out, input_sequence, sequence, i +1
def condition(conv_out, input_sequence, sequence, i):
return i < 1
i = tf.Variable(tf.constant(0, shape=()))
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
result = tf.while_loop(condition, body, [conv_out, input_sequence, sequence, i],
shape_invariants=[tf.TensorShape([None, None,None]), tf.TensorShape([None,None,None]), tf.TensorShape([None,None,None]), tf.TensorShape(())])
for r in result:
print(r.eval())
print("\n")