python - 为什么 tf.Print() 不起作用?

标签 python python-3.x tensorflow

我有这段代码:

import tensorflow as tf
import numpy as np

    # batch x time x events x dim
batch = 2
time = 3
events = 4
tensor = np.random.rand(batch, time, events)

tensor[0][0][2] = 0
tensor[0][0][3] = 0

tensor[0][1][3] = 0

tensor[0][2][1] = 0
tensor[0][2][2] = 0
tensor[0][2][3] = 0

tensor[1][0][3] = 0

def cum_sum(prev, cur):
    non_zeros = tf.equal(cur, 0.)
    tf.Print(non_zeros, [non_zeros], "message ")
    tf.Print(cur, [cur])
    return cur

elems = tf.constant([1,2,3],dtype=tf.int64)
#alternates = tf.map_fn(lambda x: (x, 2*x, -x), elems, dtype=(tf.int64, tf.int64, tf.int64))
cum_sum_ = tf.scan(cum_sum, tensor)

s = tf.Session()

s.run(cum_sum_)

我在传递给 tf.scan 的函数中有两个 tf.Print 语句,但是当我运行累计和时,我没有得到任何打印声明。我做错了什么吗?

最佳答案

tf.Print 不是那样工作的。打印节点需要进入图形才能执行。我强烈建议您查看 this教程以了解如何使用它。

如果您有任何问题,请随时提出。

关于python - 为什么 tf.Print() 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51422833/

相关文章:

python - python中两个具有相同值的不同字符串对象

python - 无法让 Mercurial 的 hgweb.cgi 在 IIS7 上工作

python - 基于条件的格式编号

python - 如何修复 ImportError : cannot import name 'Event' in Dash from plotly (python)?

python-3.x - Plotly 无法为多个跟踪器返回选定数据点的信息

python - Anaconda Jupyter 笔记本内核问题

python - 在 Python 3.6+ 中按位置高效访问字典项目

python - Facebook 连接 django/python

tensorflow - ValueError : Tensor Tensor(. ..) 不是该图的元素。使用全局变量 keras 模型时

graph - tensorflow : how to insert custom input to existing graph?