AttributeError: 'Tensor' object has no attribute 'numpy'

左心房为你撑大大i 提交于 2019-12-01 16:16:13

I suspect the place where you copied the code from had eager execution enabled, i.e. had invoked tf.enable_eager_execution() at the start of the program.

You could do the same. Hope that helps.

tf.multinomial returns a Tensor object that contains a 2D list with drawn samples of shape [batch_size, num_samples]. Calling .eval() on that tensor object is expected to return a numpy ndarray.

Something like this:

predicted_id = tf.multinomial(tf.exp(predictions), num_samples=1)[0][0].eval()

You also need to ensure that you have a session active (doesn't make a lot of sense otherwise):

sess = tf.Session()
with sess.as_default():
    predicted_id = tf.multinomial(tf.exp(predictions), num_samples=1)[0][0].eval()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!