我有个模特:
def __init__(params):
seq2seq() {
outputs, states = rnn.rnn(...)
}
def step()
...
session.run(output_feed, input_feed)这一模式是通过以下方式来调用的:
with tf.Session as sess:
model = create_model(sess) (does __init__, loads checkpoint)
inputs = ...
outputs = model.step(sess, inputs)如何打印/保存/查看rnn.rnn()返回的“状态”?
我试过tf.Print(状态-1,[状态-1]),它给了我张量的形状。
Tensor("model/seq2seq/Print:0", shape=TensorShape([Dimension(None), Dimension(4096)]), dtype=float32)我尝试了stats-1.val(),它提供了一系列错误,如:
Compute status: Invalid argument:
You must feed a value for placeholder tensor 'encoder1' with dtype int32 我还尝试将var添加到模型中以返回它,但这没有起作用:
def __init__():
...
self.state = state
def step():
output_feed.append(self.state)
result = session.run(output_feed, input_feed)
return result发布于 2016-04-05 08:57:30
为了在eval方法中看到张量的值,您不能依赖于图中的任何占位符。在本例中,错误消息告诉您states[-1]依赖于'encoder1'。
您可以在占位符的值中调用seesion.run和feed,如下所示:
session.run(states[-1], feed_dict={encoder1:[#values for encoder1 here
]})其中encoder1是占位符对象。这将返回states[-1]的值,然后可以序列化以保存该值。
在您的具体情况下,encoder1可能是rnn中的内部占位符,因此您可能希望运行如下所示:
_, state_values = session.run([output_feed, states[-1]], input_feed)若要在运行变量的上下文中获取变量的值,请执行以下操作。
https://stackoverflow.com/questions/36413949
复制相似问题