【Tensorflow】tf.Graph()函数
来源:互联网 发布:html5网购商城源码 编辑:程序博客网 时间:2024/06/08 15:07
TensorFlow是谷歌基于DistBelief进行研发的第二代人工智能学习系统,其命名来源于本身的运行原理。Tensor(张量)意味着N维数组,Flow(流)意味着基于数据流图的计算,TensorFlow为张量从流图的一端流动到另一端计算过程。TensorFlow是将复杂的数据结构传输至人工智能神经网中进行分析和处理过程的系统。
TensorFlow可被用于语音识别或图像识别等多项机器深度学习领域,对2011年开发的深度学习基础架构DistBelief进行了各方面的改进,它可在小到一部智能手机、大到数千台数据中心服务器的各种设备上运行。TensorFlow将完全开源,任何人都可以用。
原生接口文章
- 【Tensorflow】tf.placeholder函数
- 【TensorFlow】tf.nn.conv2d是怎样实现卷积的
- 【TensorFlow】tf.nn.max_pool实现池化操作
- 【Tensorflow】tf.nn.relu函数
- 【Tensorflow】tf.reshape 函数
- 【Tensorflow】tf.nn.dropout函数
- 【Tensorflow】tf.argmax函数
- 【Tensorflow】tf.cast 类型转换 函数
- 【Tensorflow】tf.train.AdamOptimizer函数
- 【Tensorflow】tf.Graph()函数
- 【TensorFlow】tf.nn.softmax_cross_entropy_with_logits的用法
- 【Tensorflow】tf.dynamic_partition 函数 分拆数组
- 【Tensorflow】实现简单的卷积神经网络CNN实际代码
- 【Tensorflow 实战】实现欧式距离
- 【Tensorflow】tensorflow.contrib.slim 包
- 【Tensorflow slim】 slim.arg_scope的用法
- 【Tensorflow slim】slim.data包
- 【Tensorflow slim】slim evaluation 函数
- 【Tensorflow slim】slim layers包
- 【Tensorflow slim】slim learning包
- 【Tensorflow slim】slim losses包
- 【Tensorflow slim】slim nets包
- 【Tensorflow slim】slim variables包
- 【Tensorflow slim】slim metrics包
- 【Tensorflow slim 实战】写MobileNet
- 【Tensorflow slim 实战】写Inception-V4 Inception-ResNet-v2结构
- 【Tensorflow keras】Keras:基于Theano和TensorFlow的深度学习库
- 【Tensorflow keras】轻量级深度学习框架 Keras简介
- 将非RGB图片转换为RGB图片
- 【opencv】python3 将图片生成视频文件
- 【opencv】selective_search函数
=========================================================================
tf.Graph() 函数非常重要,注意提现在两个方面
1. 它可以通过tensorboard用图形化界面展示出来流程结构
2. 它可以整合一段代码为一个整体存在于一个图中
声明情况大体有三种
1. tensor:通过张量本身直接出graph
# -*- coding: utf-8 -*- import tensorflow as tfc = tf.constant(4.0)sess = tf.Session()sess.run(tf.global_variables_initializer())c_out = sess.run(c)print(c_out)print(c.graph == tf.get_default_graph())print(c.graph)print(tf.get_default_graph())输出
4.0True<tensorflow.python.framework.ops.Graph object at 0x7f382f9ef110><tensorflow.python.framework.ops.Graph object at 0x7f382f9ef110>
2.通过声明一个默认的,然后定义张量内容,在后面可以调用或保存
# -*- coding: utf-8 -*- import tensorflow as tfg = tf.Graph()with g.as_default(): c = tf.constant(4.0)sess = tf.Session(graph=g)c_out = sess.run(c)print(c_out)print(g)print(tf.get_default_graph())
输出
4.0<tensorflow.python.framework.ops.Graph object at 0x7f65f1cb2fd0><tensorflow.python.framework.ops.Graph object at 0x7f65de447c90>
3.通过多个声明,在后面通过变量名来分别调用
# -*- coding: utf-8 -*- import tensorflow as tfg1 = tf.Graph()with g1.as_default(): c1 = tf.constant(4.0)g2 = tf.Graph()with g2.as_default(): c2 = tf.constant(20.0)with tf.Session(graph=g1) as sess1: print(sess1.run(c1))with tf.Session(graph=g2) as sess2: print(sess2.run(c2))
输出
4.020.0
对graph的操作大体有三种
1.保存
# -*- coding: utf-8 -*- import tensorflow as tfg1 = tf.Graph()with g1.as_default(): # 需要加上名称,在读取pb文件的时候,是通过name和下标来取得对应的tensor的 c1 = tf.constant(4.0, name='c1')g2 = tf.Graph()with g2.as_default(): c2 = tf.constant(20.0)with tf.Session(graph=g1) as sess1: print(sess1.run(c1))with tf.Session(graph=g2) as sess2: print(sess2.run(c2))# g1的图定义,包含pb的path, pb文件名,是否是文本默认Falsetf.train.write_graph(g1.as_graph_def(),'.','graph.pb',False)
输出
4.020.0并且在当前文件夹下面生成graph.pb文件
2.从pb文件中调用
# -*- coding: utf-8 -*- import tensorflow as tffrom tensorflow.python.platform import gfile#load graphwith gfile.FastGFile("./graph.pb",'rb') as f: graph_def = tf.GraphDef() graph_def.ParseFromString(f.read()) tf.import_graph_def(graph_def, name='')sess = tf.Session()c1_tensor = sess.graph.get_tensor_by_name("c1:0")c1 = sess.run(c1_tensor)print(c1)
输出
4.0
3.穿插调用
# -*- coding: utf-8 -*- import tensorflow as tfg1 = tf.Graph()with g1.as_default(): # 声明的变量有名称是一个好的习惯,方便以后使用 c1 = tf.constant(4.0, name="c1")g2 = tf.Graph()with g2.as_default(): c2 = tf.constant(20.0, name="c2")with tf.Session(graph=g2) as sess1: # 通过名称和下标来得到相应的值 c1_list = tf.import_graph_def(g1.as_graph_def(), return_elements = ["c1:0"], name = '') print(sess1.run(c1_list[0]+c2))
输出
24.0
当然还有很多比较好的地方,比如graph中自带的名称函数,通过with写的内容丰富的代码块,这里就不讲了
阅读全文
0 0
- 【Tensorflow】tf.Graph()函数
- 【Tensorflow】tf.placeholder函数
- 【Tensorflow】tf.reshape 函数
- 【Tensorflow】tf.argmax函数
- Tensorflow tf.placeholder函数
- 【Tensorflow】tf.placeholder函数
- 【Tensorflow】tf.concat函数
- 【tensorflow】打印Tensorflow graph中的所有变量--tf.trainable_variables()
- TensorFlow-tf.nn.conv2d 函数
- 【Tensorflow】tf.nn.relu函数
- 【Tensorflow】tf.nn.dropout函数
- 【Tensorflow】tf.train.AdamOptimizer函数
- TensorFlow- tf.argmax 函数学习
- TensorFlow插曲--tf.argmax函数
- tensorflow函数 tf.nn.xw_plus_b
- TensorFlow-tf.clip_by_global_norm函数原理
- TensorFlow函数:tf.nn.in_top_k()
- tensorflow--tf.one_hot()函数示例
- 阿姆斯壮数(c/python)
- java Lesson08总结
- 定义设计原则,驱动设计决策
- eclipse集成反编译插件
- 回首Java——希尔排序(最小增量排序)
- 【Tensorflow】tf.Graph()函数
- 工业设计师是怎样转型为用户体验设计师的
- Android studio设置鼠标悬停上会显示文档提示
- linux系统中统计文件夹下文件个数
- 自定义View之自定义开关
- 装饰器partial、update_wrapper、wraps作用以及如何使用
- 12864移植到STM32平台
- 第二届全国智能制造(中国制造2025)创新创业大赛西南赛区决赛开赛在即,首届中国(重庆)产业智能化创新发展论坛同期举办
- struts2和servlet同时用(访问servlet时被struts2过滤器拦截问题的解决)