如何修复此错误我从GitHub下载了此代码.
predicted_id = tf.multinomial(tf.exp(predictions), num_samples=1)[0][0].numpy()
Run Code Online (Sandbox Code Playgroud)
抛出错误
AttributeError: 'Tensor' object has no attribute 'numpy'
Run Code Online (Sandbox Code Playgroud)
请帮我解决这个问题!
我用了:
sess = tf.Session()
with sess.as_default():
predicted_id = tf.multinomial(tf.exp(predictions), num_samples=1)[0][0].eval()
Run Code Online (Sandbox Code Playgroud)
我得到这个错误.有人帮助我,我只是想让它工作为什么这么难?
D:\Python>python TextGenOut.py
File "TextGenOut.py", line 72
predicted_id = tf.multinomial(tf.exp(predictions), num_samples=1)[0][0].eval()
^
IndentationError: unexpected indent
D:\Python>python TextGenOut.py
2018-09-16 21:50:57.008663: I T:\src\github\tensorflow\tensorflow\core\platform\cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2018-09-16 21:50:57.272973: W T:\src\github\tensorflow\tensorflow\core\framework\op_kernel.cc:1275] OP_REQUIRES failed at resource_variable_ops.cc:480 : Not found: Container localhost does not exist. (Could not find resource: localhost/model/embedding/embeddings) …Run Code Online (Sandbox Code Playgroud) TensorFlow 和 Keras中的符号张量是什么?它们与其他张量有何不同?它们为什么会存在?它们在 TensorFlow 和 Keras 中出现在哪里?我们应该如何处理它们,或者在处理它们时会面临哪些问题?
过去,我遇到过一些与符号张量相关的问题,例如_SymbolicException,但文档没有描述这个概念。还有另一篇文章也提出了这个问题,但是,在这篇文章中,我专注于这个特定问题,以便以后可以将答案用作参考。
我在tensorflow中创建了一个OP,在其中进行一些处理时需要将我的数据从张量对象转换为numpy数组。我知道我们可以使用tf.eval()或sess.run评估任何张量对象。我真正想知道的是,有没有办法在无需运行任何会话的情况下将张量转换为数组,因此我们又避免使用.eval()or .run()。
任何帮助深表感谢!
def tensor_to_array(tensor1):
'''Convert tensor object to numpy array'''
array1 = SESS.run(tensor1) **#====== need to bypass this line**
return array1.astype("uint8")
def array_to_tensor(array):
'''Convert numpy array to tensor object'''
tensor_data = tf.convert_to_tensor(array, dtype=tf.float32)
return tensor_data
Run Code Online (Sandbox Code Playgroud)