AttributeError: module ‘tensorflow‘ has no attribute ‘app‘ TensorFlow2解决办法

运行报错: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()

相关推荐

  1. vue2对象丢失响应式解决办法

    2023-12-19 21:08:02       62 阅读
  2. ROS执行命令发现找不到python2.7解决办法

    2023-12-19 21:08:02       60 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-19 21:08:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-19 21:08:02       100 阅读
  3. 在Django里面运行非项目文件

    2023-12-19 21:08:02       82 阅读
  4. Python语言-面向对象

    2023-12-19 21:08:02       91 阅读

热门阅读

  1. 【PHP】身份证正则验证、校验位验证

    2023-12-19 21:08:02       61 阅读
  2. 考研英语语法(十九)

    2023-12-19 21:08:02       47 阅读
  3. Android Studio Gradle构建很慢,下载依赖缓慢问题

    2023-12-19 21:08:02       59 阅读
  4. 如何做到页面实时刷新

    2023-12-19 21:08:02       52 阅读
  5. ubuntu vscode 设置Maple font字体

    2023-12-19 21:08:02       72 阅读
  6. ubuntu22安装python3虚拟环境

    2023-12-19 21:08:02       48 阅读
  7. uni-app基本标签

    2023-12-19 21:08:02       56 阅读
  8. Python基础-字符串

    2023-12-19 21:08:02       49 阅读