用 tensorflow-gpu 2.0.0-beta1 跑程序時(shí)出現(xiàn)錯(cuò)誤
錯(cuò)誤 Error
AttributeError: module 'tensorflow' has no attribute 'keras'
相關(guān)代碼 Code
content_path = tf.keras.utils.get_file('turtle.jpg','https://storage.googleapis.com/download.tensorflow.org/example_images/Green_Sea_Turtle_grazing_seagrass.jpg')
原因 Reason
tensorflow版本沖突咧欣,因?yàn)榄h(huán)境中還裝了tensorflow1.13版本
tf.keras
需要1.14及以上的版本
解決方法 Solution
- 如果你只需要tf v1版本,更新即可:
pip install --upgrade tensorflow
- 如果你需要tf v2版本拄轻,或是和我一樣情況:
最好卸載根除所有tensorflow版本肖方,再重新安裝
方法1:pip uninstall tensorflow
方法2:打開(kāi)環(huán)境的路徑,刪除tensorflow package相關(guān)文件夾:
1)打開(kāi)Anaconda3路徑:...\Anaconda3\envs\[your_env_name]\lib\site-packages
2)刪除所有關(guān)于tensorflow的package文件夾:
tensorflow_packages.png
3)重新安裝:pip install tensorflow-gpu==2.0.0-beta1
Reference: https://github.com/tensorflow/tensorflow/issues/16614