【问题标题】:Tf.where doesn't evaluateTf.where 不评估
【发布时间】:2019-02-07 16:02:21
【问题描述】:
sess = tf.InteractiveSession()
t = tf.expand_dims(tf.constant(list(range(9))), axis=1)
tf.where(t == 5).eval()

InvalidArgumentError (see above for traceback): WhereOp : Unhandled input dimensions: 0
     [[Node: Where_16 = Where[T=DT_BOOL, _device="/job:localhost/replica:0/task:0/device:CPU:0"](Where_16/condition)]]

这里发生了什么? Numpy 中对应的代码与 np.where 有效。

【问题讨论】:

  • 您不应该在会话范围内执行此操作吗?
  • 这对你有用吗? print( tf.where(tf.equal(t,5)).eval() )
  • 你能发布更长的回溯吗?如果您尝试使用 Eager Execution 而不是交互式会话运行会发生什么?

标签: numpy tensorflow


【解决方案1】:

在您的示例中,您正在评估 tf.where(False),因为 == 运算符没有为张量重载。 (更多信息,例如:TensorFlow operator overloading

试试:

sess = tf.InteractiveSession()
t = tf.expand_dims(tf.constant(list(range(9))), axis=1)
tf.where(tf.equal(t, 5)).eval()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-01
    相关资源
    最近更新 更多