Tensorflow——[AttributeError:module tensorflow no attribute app]解决方案
問題描述
import tensorflow as tf FLAGS = tf.app.flags.FLAGS File "E:\CNN\chengxu\SVM-CNN-12.22\lib\network\resnet_cifar.py", line 9, in <module>from lib.config.config import FLAGSFile "E:\CNN\chengxu\SVM-CNN-12.22\lib\config\config.py", line 16, in <module>FLAGS = tf.app.flags.FLAGS AttributeError: module 'tensorflow' has no attribute 'app'官方文檔
https://tensorflow.google.cn/install?hl=zh_cn?
https://github.com/tensorflow/tensorflow/issues/34431?
問題分析?
Tensorflow版本問題
當(dāng)使用Tensorflow2.0,而源代碼是Tensorflow1.幾版本。
解決方案
(1)將import tensorflow as tf 改為import tensorflow.compat.v1 as tf
import tensorflow.compat.v1 as tf FLAGS = tf.app.flags.FLAGS(2)用tf.compat.v1.flags替換tf.app.flags
這兩種方法都可以。個人推薦第一種。
(3)下載pycharm,選擇python版本,在pycharm里面為python創(chuàng)建對應(yīng)的虛擬環(huán)境,如果原來是tensorflow2.0版本卸載掉,安裝tensorflow 1.x版本。
記得勾選specific version 才可以安裝。?
?(4)重裝Tensorflow
pip3 uninstall tensorflow-gpu#卸載pip3 install --upgrade tensorflow-gpu #安裝參考文章
https://stackoverflow.com/questions/59272234/attributeerror-module-tensorflow-has-no-attribute-app-error?
https://blog.csdn.net/qq_24163555/article/details/102954704
https://blog.csdn.net/weixin_41012399/article/details/103654641
https://www.jianshu.com/p/9b801ecc5fe8
總結(jié)
以上是生活随笔為你收集整理的Tensorflow——[AttributeError:module tensorflow no attribute app]解决方案的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C++——《算法分析与设计》实验报告——
- 下一篇: Tensorflow——[Could n