码迷,mamicode.com
首页 > 其他好文 > 详细

第一节 图的概念

时间:2020-03-30 12:37:31      阅读:77      评论:0      收藏:0      [点我收藏+]

标签:sum   创建   会话   ssi   style   class   定义   const   级别   

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)
    # 

 

第一节 图的概念

标签:sum   创建   会话   ssi   style   class   定义   const   级别   

原文地址:https://www.cnblogs.com/kogmaw/p/12597596.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!