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
|
import numpy as np
import tensorflow as tf
sess = tf.Session()
#idx = tf.constant([[0,2],[1,2]])
# 4 x 2 | 40K x 256
m = tf.Variable([[1,2],
[0,0],
[0,0],
[0,0]], dtype=tf.float32)
# -> 2 x 4 | 256 x 40K
m_transposed = tf.transpose(m)
# -> AttributeError: 'Tensor' object has no attribute '_lazy_read'
m_new = tf.Variable([[1., 0., 0., 0.],
[2., 0., 0., 0.]], dtype=tf.float32)
# 1 x 3 | 1 x Y
idx = tf.constant([1,2,3], dtype=tf.int32)
idx = sess.run(idx)
_idx = []
for j in idx:
for i in range(0,m_new.shape[0]):
_idx.append([i,j])
#idx_new = tf.constant(_idx, dtype=tf.int32)
idx_new = np.full(fill_value=_idx, shape=[6,2], dtype=np.int32)
# 2 x 2
up = tf.constant([[1,1],[1,1],[1,1]], dtype=tf.float32)
# 1 x 4
up_new = tf.reshape(up, [tf.size(up)])
sess.run(tf.global_variables_initializer())
print("m")
print(sess.run(m))
print("m_new")
print(sess.run(m_new))
print("m_transposed")
print(sess.run(m_transposed))
print("idx")
print(idx)
print("idx_new")
#print(sess.run(idx_new))
print(idx_new)
print("up")
print(sess.run(up))
print("up_new")
print(sess.run(up_new))
print()
print("scatter_nd_add")
print(sess.run(tf.scatter_nd_add(m_new, indices=idx_new, updates=up_new)))
print()
|