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

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 
    from lib.config.config import FLAGS
  File "E:\CNN\chengxu\SVM-CNN-12.22\lib\config\config.py", line 16, in 
    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

成功了。

你可能感兴趣的:(AttributeError: module 'tensorflow' has no attribute 'app')