【发布时间】:2016-03-19 10:33:40
【问题描述】:
以下代码可以正常工作,但使用 eval() 我认为效率低下。有没有更好的方法来达到同样的效果?
import tensorflow as tf
import numpy as np
sess = tf.Session()
t = tf.constant([[4,5.1,6.3,5,6.5,7.2,9.3,7,1,1.4],[4,5.1,9.3,5,6.5,7.2,1.3,7,1,1.4],[4,3.1,6.3,5,6.5,3.2,5.3,7,1,1.4]])
print t
a = tf.argmax(t,1).eval(session=sess)
z = [ k==np.arange(14) for k in a]
z1 = tf.convert_to_tensor(np.asarray(z).astype('int32'))
print z1
print sess.run(z1)
输出
Tensor("Const_25:0", shape=TensorShape([Dimension(3), Dimension(10)]), dtype=float32)
Tensor("Const_26:0", shape=TensorShape([Dimension(3), Dimension(14)]), dtype=int32)
[[0 0 0 0 0 0 1 0 0 0 0 0 0 0]
[0 0 1 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 1 0 0 0 0 0 0]]
【问题讨论】:
标签: eval tensorflow one-hot-encoding