第一节 图的概念

import tensorflow as tf 
import os

os.environ['TF_CPP_MIN_LOG_LEVEL']='2'
# 修改TensorFlow警告信息级别

# 创建一张图包含了op和tensor,使用图是在上下文环境中的
# op:只要用TensorFlow的API定义的函数都是op
# tensor:就是指代数据
g = tf.Graph()

print(g)
# 使用图
with g.as_default():
    c = tf.constant(11.0)
    print(c.graph)


# 图和图之间是互不干扰的
a = tf.constant(5.0)
b = tf.constant(6.0)

sum1 = tf.add(a, b)
graph = tf.get_default_graph
# 查看图对象,会默认创建一张图
print(graph)

# Session会话,只能运算一张图
with tf.Session() as sess:
    print(sess.run(sum1))
    # 输出sum1
    
    print(a.graph)
    #

    print(sum1.graph)
    #

    print(sess.graph)
    # 

猜你喜欢

转载自www.cnblogs.com/kogmaw/p/12597596.html