AttributeError: module 'tensorflow' has no attribute 'app'

做~自己de王妃 提交于 2019-12-24 05:32:58

tensorflow的版本是1.14.0
下边这句报错

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 FLAGS
  File "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'

用网上说的解决办法:
(1)将import tensorflow as tf 改为import tensorflow.compat.v1 as tf
(2)用tf.compat.v1.flags替换tf.app.flags
都没用

最后把tensorflow先升级到2.0.0。pip install --upgrade tensorflow==2.0.0
再改成

import tensorflow.compat.v1 as tf
FLAGS = tf.app.flags.FLAGS

成功了。

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!