样例代码
hello.py文件内容如下。这也是tensorflow入门级案例。其中创建了tf.Session.本文分析一下session的相关代码及依赖。
tensorflow安装在:envs/python3.10/lib/python3.10/site-packages/tensorflow目录下。也就是使用minconda的envs目录下。
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
tf.disable_eager_execution()
print(tf.__version__)
v = tf.constant(3)
print(v)
print(tf.Session)
with tf.Session() as sess:
vv = sess.run(v)
print(vv)
以下是输出
$ python hello.py
WARNING:tensorflow:From /data0/huozai/miniconda2/envs/python3.10/lib/python3.10/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
2.10.0
Tensor("Const:0", shape=(), dtype=int32)
<class 'tensorflow.python.client.session.Session'>
2022-05-15 21:08:36.578359: I tensorf