【问题标题】:How to print a plain text constant in tensorflow eager execution mode如何在 tensorflow 急切执行模式下打印纯文本常量
【发布时间】:2019-07-30 14:02:27
【问题描述】:

我已经在 tensorflow 中初始化了一个常量:

hello = tf.constant('hello')

在普通模式下,print(sess.run(hello).decode()) 以常量张量输出纯文本。

然而,在急切执行模式下,上面的代码不起作用。

如何在常量 Tensor hello 中打印纯文本?

这个问题与python b'str'tf sess.run 无关

【问题讨论】:

  • @ShubhamPanchal print( hello ) 给出 'tf.Tensor(b'hello', shape=(), dtype=string)',我只想要 'hello' 部分

标签: python tensorflow


【解决方案1】:

将张量转换为numpy数组然后解码

print(hello.numpy().decode())

【讨论】:

    猜你喜欢
    • 2018-11-23
    • 1970-01-01
    • 2019-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-19
    • 1970-01-01
    • 2019-06-23
    相关资源
    最近更新 更多