weixin_47696437 2022-02-11 19:56 采纳率: 85.3%
浏览 525
已结题

测试tensorflow2版本问题 ,出现告警以及错误。

问题遇到的现象和发生背景

在anaconda4.11.0上测试安装的tensorflow2.8.0。

问题相关代码,请勿粘贴截图

import tensorflow as tf
hello = tf.constant('hello,tensorf')
sess = tf.Session()
print(sess.run(hello))
出现:
AttributeError: module 'tensorflow' has no attribute 'Session'

img

自己查找修改为:
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
hello = tf.constant('hello,tensorf')
sess = tf.Session()
print(sess.run(hello))
结果还是错误

运行结果及报错内容

WARNING:tensorflow:From D:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\compat\v2_compat.py:107: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version.
Instructions for updating:
non-resource variables are not supported in the long term
b'hello,tensorf'
为什么出现 b'hello,tensorf'这个结果

我的解答思路和尝试过的方法

我想要达到的结果

'hello,tensorf'

  • 写回答

1条回答 默认 最新

  • weixin_47696437 2022-02-11 20:08
    关注

    查询网络一些答案,修改代码后,无错误,
    import tensorflow.compat.v1 as tf
    tf.disable_v2_behavior()
    hello = tf.constant('hello,tensorf')
    sess = tf.Session()
    sess.run(hello)
    print(sess.run(hello))

    但是代码运行结果咋是b'hello,tensorf'?怎么多了个b'

    img

    评论

报告相同问题?

问题事件

  • 系统已结题 2月19日
  • 创建了问题 2月11日

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题