运行报错:AttributeError: module ‘tensorflow’ has no attribute ‘app’
原因:用TensorFlow2运行TensorFlow1的代码,有可能会报这个错误。
解决办法:其实他在TensorFlow1中就是一个函数入口的,那种
(1)将import tensorflow as tf 改为import tensorflow.compat.v1 as tf
(2)用tf.compat.v1.flags替换tf.app.flags
大概率不适用。
解决办法直接换成你的入口函数,一般是tf.app.run()替换成main()
ag.顺便写一下在TensorFlow1中的用法:如果你的代码中的入口函数不叫main(),而是一个其他名字的函数,如test(),则你应该这样写入口tf.app.run(test)
如果你的代码中的入口函数叫main(),则你就可以把入口写成tf.app.run()
AttributeError: module ‘tensorflow‘ has no attribute ‘app‘ TensorFlow2解决办法
最新推荐文章于 2024-03-18 21:14:26 发布
本文介绍了在从TensorFlow1升级到TensorFlow2时,遇到AttributeError:moduletensorflowhasnoattributeapp的问题。解决方法包括使用`importtensorflow.compat.v1astf`代替原导入方式,并可能需要调整入口函数,如将`tf.app.run()`替换为`main()`或特定函数名。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
TensorFlow-v2.9
TensorFlow
TensorFlow 是由Google Brain 团队开发的开源机器学习框架,广泛应用于深度学习研究和生产环境。 它提供了一个灵活的平台,用于构建和训练各种机器学习模型
2万+





