tensorflow if语句

来源:互联网 发布:重庆编程培训 编辑:程序博客网 时间:2024/06/11 14:54

 tf:

cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=y_, labels=y))  # tf.nn.l2_loss(W['out'])

        cost_b = tf.nn.l2_loss(W['out'])
        c_ = tf.cond(cost < cost_b, lambda: 0.85 * cost / cost_b, lambda: c)
        cost = cost + cost_b * c_

等价于:

if cost_b > cost:

c_ = 0.85 * cost / cost_b

else:

c_ = c

但lambda:后的对象必须为tf中的对象,且必须有值。

原创粉丝点击