tf2.0运行sess.run报错

@[toc](AttributeError: module ‘tensorflow’ has no attribute ‘Session’())

sess = tf.Session()
sess.run()

运行上面一行代码的时候会报错 AttributeError: module ‘tensorflow’ has no attribute ‘Session’(),tf1.0是可以执行的,但是tf 2.0以后移除了tf.Session,要是想用这Session的话,得改为

sess = tf.compat.v1.Session()

并且要在开头加一行,一定要加在最前面,import下面就行,我试过了,要是加在中间,还是会报错。

tf.compat.v1.disable_eager_execution()

这样就ok了。

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
文件夹 PATH 列表 卷序列号为 4E8D-6931 C:. │ .txt │ assess.zip │ └─assess │ assess.sql │ pom.xml │ ├─.idea │ │ assess.eml │ │ assess.iml │ │ compiler.xml │ │ encodings.xml │ │ misc.xml │ │ modules.xml │ │ uiDesigner.xml │ │ webContexts.xml │ │ workspace.xml │ │ │ ├─artifacts │ │ assess_war.xml │ │ assess_war_exploded.xml │ │ │ └─libraries │ Maven__javax_servlet_javax_servlet_api_4_0_1.xml │ Maven__javax_servlet_jstl_1_2.xml │ Maven__mysql_mysql_connector_java_5_1_38.xml │ ├─src │ └─main │ ├─java │ │ └─com │ │ └─demo │ │ ├─bean │ │ │ UserBean.java │ │ │ │ │ ├─dao │ │ │ JdbcUtils.java │ │ │ │ │ ├─service │ │ │ UserService.java │ │ │ │ │ └─web │ │ └─controller │ │ LoginController.java │ │ UserController.java │ │ │ ├─resources │ └─webapp │ │ add.jsp │ │ index.jsp │ │ login.jsp │ │ modify.jsp │ │ │ ├─assets │ │ └─bootstrap-3.3.7 │ │ ├─css │ │ │ bootstrap-theme.css │ │ │ bootstrap-theme.css.map │ │ │ bootstrap-theme.min.css │ │ │ bootstrap-theme.min.css.map │ │ │ bootstrap.css │ │ │ bootstrap.css.map │ │ │ bootstrap.min.css │ │ │ bootstrap.min.css.map │ │ │ │ │ ├─fonts │ │ │ glyphicons-halflings-regular.eot │ │ │ glyphicons-halflings-regular.svg │ │ │ glyphicons-halflings-regular.ttf │ │ │ glyphicons-halflings-regular.woff │ │ │ glyphicons-halflings-regular.woff2 │ │ │ │ │ └─js │ │ bootstrap.js │ │ bootstrap.min.js │ │ npm.js │ │ │ ├─images │ │ background.png │ │ │ └─WEB-INF │ web.xml │ └─target ├─assess-1.0.0-SNAPSHOT │ │ add.jsp │ │ index.jsp │ │ login.jsp │ │ modify.jsp │ │ │ ├─assets │ │ └─bootstrap-3.3.7 │ │ ├─css │ │ │ bootstrap-theme.css │ │ │ bootstrap-theme.css.map │ │ │ bootstrap-theme.min.css │ │ │ bootstrap-theme.min.css.map │ │ │ bootstrap.css │ │ │ bootstrap.css.map │ │ │ bootstrap.min.css │ │ │ bootstrap.min.css.map │ │ │ │ │ ├─fonts │ │ │ glyphicons-halflings-regular.eot │ │ │ glyphicons-halflings-regular.svg │ │ │ glyphicons-halflings-regular.ttf │ │ │ glyphicons-halflings-regular.woff │ │ │ glyphicons-halflings-regular.woff2 │ │ │ │ │ └─js │ │ bootstrap.js │ │ bootstrap.min.js │ │ npm.js │ │ │ ├─images │ │ background.png │ │ │ ├─META-INF │ │ MANIFEST.MF │ │ │ └─WEB-INF │ │ web.xml │ │ │ ├─classes │ │ └─com │ │ └─demo │ │ ├─bean │ │ │ UserBean.class │ │ │ │ │ ├─dao │ │ │ JdbcUtils.class │ │ │ │ │ ├─service │ │ │ UserService.class │ │ │ │ │ └─web │ │ └─controller │ │ LoginController.class │ │ UserController.class │ │ │ └─lib │ jstl-1.2.jar │ mysql-connector-java-5.1.38.jar │ ├─classes │ └─com │ └─demo │ ├─bean │ │ UserBean.class │ │ │ ├─dao │ │ JdbcUtils.class │ │ │ ├─service │ │ UserService.class │ │ │ └─web │ └─controller │ LoginController.class │ UserController.class │ └─generated-sources └─annotations

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值