【问题标题】:How to print full (not truncated) tensor in tensorflow?如何在张量流中打印完整(未截断)张量?
【发布时间】:2018-03-22 13:17:25
【问题描述】:

每当我尝试打印时,我总是得到截断的结果

import tensorflow as tf
import numpy as np

np.set_printoptions(threshold=np.nan)

tensor = tf.constant(np.ones(999))

tensor = tf.Print(tensor, [tensor])

sess = tf.Session()

sess.run(tensor)

如您所见,我遵循了在 Print full value of tensor into console or write to file in tensorflow 上找到的指南

但输出很简单

...\core\kernels\logging_ops.cc:79] [1 1 1...]

我想查看完整的张量,谢谢。

【问题讨论】:

    标签: numpy tensorflow


    【解决方案1】:

    通过检查the Tensorflow API 中的tf.Print 可以轻松解决此问题。传递summarize=n,其中n 是您要显示的元素数。

    【讨论】:

    【解决方案2】:

    您可以在 TensorFlow 2.x 中进行如下操作:

    import tensorflow as tf
    
    tensor = tf.constant(np.ones(999))
    tf.print(tensor, summarize=-1)
    

    来自 TensorFlow 文档 -> 汇总:每个维度中的第一个和最后一个汇总元素按张量递归打印。如果设置为 -1,它将打印每个张量的所有元素。

    https://www.tensorflow.org/api_docs/python/tf/print

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-09
      • 1970-01-01
      • 1970-01-01
      • 2021-12-16
      • 1970-01-01
      • 2023-01-11
      • 1970-01-01
      • 2018-04-18
      相关资源
      最近更新 更多