解决 AttributeError: module ‘tensorflow‘ has no attribute ‘app‘

1、项目场景:

运行tensorflow的代码报错:
Traceback (most recent call last):
File “E:/Pycharm/LotteryPrediction/ssq-master/ssq.py”, line 25, in
tf.app.flags.DEFINE_integer(‘batch_size’, -1, ‘batch size.’)
AttributeError: module ‘tensorflow’ has no attribute ‘app’


2、原因分析:

安装的tensorflow是2.0版本的,所以会报这个错误。


3、解决方案:

修改如下:

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

猜你喜欢

转载自blog.csdn.net/qq_44368508/article/details/126992689