state = cell.zero_state(batchsize, tf.float32).eval()
我正在尝试关注这个 https://github.com/kvfrans/twitch/blob/master/sample.py#L45解码和运行经过训练的 tensorflow 模型的示例,但似乎使用的 tensorflow 代码是旧版本。我已经设法修复了对 v 1.0.0 的大多数调用,但我被困在上面的代码行给我以下错误的地方:
Traceback (most recent call last):
File "server.py", line 1, in <module>
from sample import *
File "/home/user/twitch/sample.py", line 75, in <module>
print predict("this game is")
File "/home/user/twitch/sample.py", line 46, in predict
state = initialstate.eval()
AttributeError: 'tuple' object has no attribute 'eval'
关于如何修复 .eval()
和 state
有什么想法吗?它稍后用于:
guessed_logits, state = sess.run([logits, final_state], feed_dict={input_data: primer, initialstate: state})
最佳答案
.eval()
method 仅在 tf.Tensor
上实现,但正如其他人所观察到的,cell.zero_state()
方法返回一个 tuple
对象。
tf.Session.run()
方法了解如何解包元组,而 tf.Tensor.eval()
只是一个方便的包装器,用于调用 tf.Session.run()
"default" session 中的单个张量。使用此观察,您可以切换此行:
state = cell.zero_state(batchsize, tf.float32).eval()
...具有以下内容:
state = tf.get_default_session().run(cell.zero_state(batchsize, tf.float32))
关于python - Tensorflow:AttributeError: 'tuple' 对象没有属性 'eval',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42677650/