【问题标题】:how to output the states of lstm gates in tensorflow?如何在张量流中输出 lstm 门的状态?
【发布时间】:2016-12-01 11:05:30
【问题描述】:

我想查看 lstm 门的激活状态,但似乎要获取门状态并将其输出到文件并不容易。

我可以在 BasicLSTM 中使用“tf.Print”函数,如下所示:
gate = tf.Print(gate, [sigmoid(gate)])
但“tf.Print”在终端中显示此门,例如:
gate name : [0.5222222, 0.444444, 0.3333333, ...]
我无法得到这个门的所有值,只是“......”。而且我必须使用重定向将它们输出到文件。


感谢@ben,我可以使用tf.Print(gate, [sigmoid(gate)], summarize=10000000) 来解决“...”。但是也需要重定向来将它们输出到文件中。


我也尝试在 BasicLSTM 中为门指定一个名称:
gate = tf.identity(gate_tmp, "gate")
然后,我可以使用
gate = tf.get_default_graph().get_tensor_by_name("model/RNN/while/BasicLSTMCell/gate:0")
按名称获取此张量 但是当我sess.run(gate)
发生错误,“gate is not fetchable”

所以我将“门”更改为变量。
gate = tf.Variable(gate, trainable=False)
但是出现了一个新错误,“节点 model_1/Variable_1/Assign 的所有输入必须来自同一帧。”

那么,我应该如何获取 LSTM 门的状态?并将它们输出到文件中?

【问题讨论】:

  • 你是如何将门张量从 BasicLSTM 模块返回到你的主应用程序的?我正在尝试更改 TF 源代码以将此张量与 new_h、new_state 元组一起返回,但错误太多。

标签: tensorflow recurrent-neural-network lstm


【解决方案1】:

tf.Print 支持特殊参数“summarize”来控制打印元素的数量:例如你可以使用

tf.Print(gate, [sigmoid(gate)], summarize=10000000) 

【讨论】:

  • 它有效,但我想将它们输出到文件中。除了重定向还有什么办法?
猜你喜欢
  • 2023-03-21
  • 1970-01-01
  • 2018-03-25
  • 2016-05-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多