gpt4 book ai didi

tensorflow - tensorflow 中的条件打印节点

转载 作者:行者123 更新时间:2023-12-05 06:33:19 28 4
gpt4 key购买 nike

我正在寻找一种在 tensorflow 中有条件打印节点的方法,使用下面的示例代码行,其中每 10 个循环计数,它应该在控制台中打印一些东西。但这对我不起作用。谁能建议?

谢谢,哈米德雷萨,

epsilon = tf.cond(tf.constant(counter % 10 == 0, dtype=tf.bool), true_fn=lambda:tf.Print(epsilon, [counter, epsilon], 'batch: ', summarize=10), false_fn=lambda:epsilon)

最佳答案

我遇到了类似的问题,并通过以下丑陋的解决方案解决了它。

我正在使用 tf.print 而不是“tf.Print”,因为它已被解密:

由于 true_func 和 false_func 应该返回相同的类型和形状,所以我返回一个无意义的常量。

def true_func():
printfunc = tf.print(TENSOR_TO_PRINT,summarize=-1)
with tf.control_dependencies([printfunc]):
return tf.constant(1)

def false_func():
return tf.constant(1)

shouldprint = tf.cond(YOUR_CONDITION ,true_fn = true_func ,false_fn=false_func)

然后您可以运行 shouldprint 操作或将其添加为其他操作的依赖项。

关于tensorflow - tensorflow 中的条件打印节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50830960/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com