1. 程式人生 > >tensorflow 出錯module 'tensorflow' has no attribute 'layers'

tensorflow 出錯module 'tensorflow' has no attribute 'layers'

出錯:module 'tensorflow' has no attribute 'layers'

解決方法:由於已經安裝的tensorflow是0.x的版本,0.x版本沒有layers模組所以程式出錯,需要重新安裝tensorflow 1.0以上的版本,即更新tensorflow版本。

檢視目前tensorflow版本

pip list

顯示:如下圖,此時的tensorflow為0.12.0版本

所以需要更新版本號。

cpu版本更新:

升級方法

1、首先啟用tensorflow環境(我的環境命名是grey)

activate grey

2、輸入以下安裝命令:  GPU版本:

pip install --upgrade tensorflow-gpu

CPU版本:

pip install --upgrade tensorflow

博主為cpu版本,輸入pip install --upgrade tensorflow後回車就開始升級過程,會下載並解除安裝重灌一些必要的包,時間長短視網速而定。

經過幾分鐘的等待。更新完成:

啟動spyder 重新執行tensorflow程式。

執行結果已經沒有報錯。

哈哈哈哈!大功告成!