小编Bat*_*tta的帖子

当使用tf.cond()时,tensorflow会为不必要的占位符请求输入

请考虑以下包含tensorflow的代码段tf.cond().

import tensorflow as tf
import numpy as np

bb = tf.placeholder(tf.bool)
xx = tf.placeholder(tf.float32, name='xx')
yy = tf.placeholder(tf.float32, name='yy')

zz = tf.cond(bb, lambda: xx + yy, lambda: 100 + yy)

with tf.Session() as sess:
        dict1 = {bb:False, yy:np.array([1., 3, 4]), xx:np.array([5., 6, 7])}
        print(sess.run(zz, feed_dict=dict1)) # works fine without errors

        dict2 = {bb:False, yy:np.array([1., 3, 4])}
        print(sess.run(zz, feed_dict=dict2)) # get an InvalidArgumentError asking to
                                             # provide an input for xx
Run Code Online (Sandbox Code Playgroud)

在这两种情况下,bbis Falsezz理论上的评估都没有依赖关系 …

python machine-learning tensorflow

4
推荐指数
1
解决办法
295
查看次数

标签 统计

machine-learning ×1

python ×1

tensorflow ×1