在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'
自己查找修改为:
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'
查询网络一些答案,修改代码后,无错误,
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'