簡體   English   中英

屬性錯誤:模塊“tensorflow”沒有屬性“變量”“錯誤”

[英]AttributeError: module 'tensorflow' has no attribute 'Variable' “ERROR”

我已經使用了一天的 tensor-flow,但是出現了一些麻煩,當我導入 tensor-flow 時,會出現 AttributeError: 'module' object has no attribute 'variable'

我使用 Windows10、Python 3.5.3、Anaconda-3 4.4.0

這是我的測試代碼:

import tensorflow as tf
my_var = tf.Variable(tf.linspace(10.0, 13.0, 4)) 
with tf.Session() as sess:
    print (sess.run(my_var))

我收到此錯誤:錯誤

看起來您已經編寫了一個模塊random.py ,它random.py了標准庫的random模塊。 嘗試重命名文件並檢查錯誤是否消失。 您可以告訴它正在您發布的堆棧跟蹤底部導入您的 random.py。

將 'variable' 替換為 'Variable',例如以下代碼給出錯誤:

initial_value=tf.random.normal(shape=(2,2))
a = tf.variable(initial_value)
print(a)

但這段代碼給出了成功的輸出

initial_value=tf.random.normal(shape=(2,2))
a = tf.Variable(initial_value)
print(a)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM