2017-08-13 72 views
0

我已按照網站上的步驟完成張量流的安裝。張量流對象中沒有屬性常量

最後,當我有測試安裝

import tensorflow as tf 

上面一行被沒有任何錯誤的解釋,但是,當我用

tf.constant ('hello') 

它提供了追蹤和錯誤,指出tensorflow沒有名爲常量的屬性。

我使用的是Mac OSX與Python 3

+0

*以上行獲取,沒有錯誤interpretted * **這上面一行** – Ravi

+0

後'進口tensorflow爲tf',可以打印的價值? 'dir(tf)'並將其添加到您的問題? – mrry

回答

0

對於tensorflow,記住,你必須首先建立你的圖,然後執行它。所以,在你的情況下,tf.constant('hello')將不會被執行,直到你從你的會話中調用它。 這裏有一個工作示例:

In [1]: import tensorflow as tf 
In [2]: tf.constant('hello') 
Out[2]: <tf.Tensor 'Const:0' shape=() dtype=string> 

In [3]: c = tf.constant('hello') 
In [4]: sess = tf.InteractiveSession() 

In [5]: sess.run(c) 
Out[5]: 'hello' 

正如你可以看到,我們可以有c上運行時的實際價值。

0

如果您安裝了一個,請從Tensorflow虛擬環境運行python腳本。所有與Tensorflow相關的模塊和屬性都在這裏單獨提供。

要激活的virtualenv,使用:

source ~/tensorflow/bin/activate 
相關問題