TensorFlow学习(三):Graph和Session

TuGraph开源JAVA客户端工具TuGraph-OGM,无缝对接JAVA开发生态 (预计阅读时间:7分钟) TuGraph 图数据库提供了 JAVA、C++、Python 等多种语言的 SDK 支持,方便客户在各种场景下使用。用户使用 SDK 向TuGraph服务器发送Cypher请求,服务器则以 JSON形... 阅读详情

原文地址:http://blog.youkuaiyun.com/xierhacker/article/details/53860379

更新时间:

2017.5.5

对一些函数或者类有了新的认识。重要的地方修改一下。 
简化了大量的东西,保留重点,只写了常用函数的用法,其他的根据需要看文档

之前讲完变量常量等等基本量的操作,意味着最基本的东西都有了,然后接下来很重要的就是那些量和操作怎么组成更大的集合,怎么运行这个集合。这些就是计算图谱Graph和Session的作用了。

因为篇幅和格式的缘故,这里的测试代码并没写全,全部的代码可以在我的GitHub上面找到:LearningTensorFlow/3.Graph_and_Session/

一.Graph

首先官方文档地址:tf.Graph 
这里仅列出了最基本和频繁使用的函数,更多特定的需要请参考文档。

Ⅰ.介绍

一个TensorFlow的运算,被表示为一个数据流的图。 
一幅图中包含一些操作(Operation)对象,这些对象是计算节点。前面说过的Tensor对象,则是表示在不同的操作(operation)间的数据节点

你一旦开始你的任务,就已经有一个默认的图已经创建好了。而且可以通过调用tf.get_default_graph()来访问到。 
添加一个操作到默认的图里面,只要简单的调用一个定义了新操作的函数就行。比如下面的例子展示的:

import tensorflow as tf
import numpy as np

c=tf.constant(value=1)
#print(assert c.graph is tf.get_default_graph())
print(c.graph)
print(tf.get_default_graph())
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

另外一种典型的用法就是要使用到Graph.as_default() 的上下文管理器( context manager),它能够在这个上下文里面覆盖默认的图。如下例

import tensorflow as tf
import numpy as np

c=tf.constant(value=1)
#print(assert c.graph is tf.get_default_graph())
print(c.graph)
print(tf.get_default_graph())

g=tf.Graph()
print("g:",g)
with g.as_default():
    d=tf.constant(value=2)
    print(d.graph)
    #print(g)

g2=tf.Graph()
print("g2:",g2)
g2.as_default()
e=tf.constant(value=15)
print(e.graph)
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

结果: 
这里写图片描述 
上面的例子里面创创建了一个新的图g,然后把g设为默认,那么接下来的操作不是在默认的图中,而是在g中了。你也可以认为现在g这个图就是新的默认的图了。 
要注意的是,最后一个量e不是定义在with语句里面的,也就是说,e会包含在最开始的那个图中。也就是说,要在某个graph里面定义量,要在with语句的范围里面定义。

一个Graph的实例支持任意多数量通过名字区分的的“collections”。 
为了方便,当构建一个大的图的时候,collection能够存储很多类似的对象。比如 tf.Variable就使用了一个collection(tf.GraphKeys.GLOBAL_VARIABLES),包含了所有在图创建过程中的变量。 
也可以通过之指定新名称定义其他的collection

Ⅱ.属性

building_function:Returns True iff this graph represents a function.

finalized:返回True,要是这个图被终止了

graph_def_versions:The GraphDef version information of this graph.

seed:The graph-level random seed of this graph.

version:Returns a version number that increases as ops are added to the graph.

Ⅲ.函数

__init__()

作用:创建一个新的,空的图

add_to_collection(name,value)

作用:存放值在给定名称的collection里面(因为collection不是sets,所以有可能一个值会添加很多次) 
参数: 
name: The key for the collection. The GraphKeys class contains many standard names for collections. 
value: 添加到collection中的值

as_default()

作用: 
返回一个上下文管理器,使得这个Graph对象成为当前默认的graph.当你想在一个进程里面创建多个图的时候,就应该使用这个函数.为了方便起见,一个全局的图对象被默认提供,要是你没有显式创建一个新的图的话,所有的操作(ops)都会被添加到这个默认的图里面来. 
通过with关键字和这个方法,来让这个代码块内创建的从操作(ops)添加到这个新的图里面. 
默认的是当前线程的”property”,如果你创建了一个新的线程而且想使用这个默认的图,你应该显式添加一个g.as_default(): 在这个线程函数里面. 
下面是两种写法示例:

# 1. Using Graph.as_default():
g = tf.Graph()
with g.as_default():
  c = tf.constant(5.0)
  assert c.graph is g

# 2. Constructing and making default:
with tf.Graph().as_default() as g:
  c = tf.constant(5.0)
  assert c.graph is g
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

device(*args,**kwds)

作用: 
返回一个上下文管理器(context manager)指定新创建的操作(ops)默认使用的设备。 
参数: 
device_name_or_function::在这个上下文下面使用的设备名称或者函数。这个参数可以十一个设备名称字符串,或者十一个设备函数,或者是None。

如果是设备名称字符串,那么所有的在这个上下问构建的操作(operations)都会被指派给这个名字的设备。unless overridden by a nested device() context. 
如果是一个函数,他会被当做十一个从操作对象到设备字符串的函数。每次一个新的操作生成,都会被激活,这个操作就会被只拍到函数返回的设备名称上面。 
If it is None, all device() invocations from the enclosing context will be ignored. 
For information about the valid syntax of device name strings, see the documentation in DeviceNameUtils.

例子:

with g.device('/gpu:0'):
  # All operations constructed in this context will be placed
  # on GPU 0.
  with g.device(None):
    # All operations constructed in this context will have no
    # assigned device.

# Defines a function from `Operation` to device string.
def matmul_on_gpu(n):
  if n.type == "MatMul":
    return "/gpu:0"
  else:
    return "/cpu:0"

with g.device(matmul_on_gpu):
  # All operations of type "MatMul" constructed in this context
  # will be placed on GPU 0; all other operations will be placed
  # on CPU 0.
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

finalize()

作用:结束这个graph,使得他只读(read-only).调用 g.finalize()之后,新的操作就不能够添加到g里面去了.这个函数是保证党图被多个线程共用的时候,没有新的操作能够添加进去.比如:tf.train.QueueRunner.

get_all_collection_keys()

作用: 
返回在graph中使用的collection列表

get_operation_by_name(name)

作用:对于给定的名称,返回操作(Operation) 
参数: 
name: 操作名称

get_operations()

作用: 
返回图中操作的列表。

get_tensor_by_name(name)

作用:返回给定名称的tensor

is_feedable(tensor)

作用:要是一个tensor能够被feed的话,返回True。

is_fetchable(tensor_or_op)

作用:要是tensor或者op能够取到,返回True

name_scope(*args,**kwds) 
Returns a context manager that creates hierarchical names for operations.

A graph maintains a stack of name scopes. A with name_scope(…): statement pushes a new name onto the stack for the lifetime of the context.

The name argument will be interpreted as follows:

A string (not ending with ‘/’) will create a new name scope, in which name is appended to the prefix of all operations created in the context. If name has been used before, it will be made unique by calling self.unique_name(name). 
A scope previously captured from a with g.name_scope(…) as scope: statement will be treated as an “absolute” name scope, which makes it possible to re-enter existing scopes. 
A value of None or the empty string will reset the current name scope to the top-level (empty) name scope. 
For example:

with tf.Graph().as_default() as g:
  c = tf.constant(5.0, name="c")
  assert c.op.name == "c"
  c_1 = tf.constant(6.0, name="c")
  assert c_1.op.name == "c_1"

  # Creates a scope called "nested"
  with g.name_scope("nested") as scope:
    nested_c = tf.constant(10.0, name="c")
    assert nested_c.op.name == "nested/c"

    # Creates a nested scope called "inner".
    with g.name_scope("inner"):
      nested_inner_c = tf.constant(20.0, name="c")
      assert nested_inner_c.op.name == "nested/inner/c"

    # Create a nested scope called "inner_1".
    with g.name_scope("inner"):
      nested_inner_1_c = tf.constant(30.0, name="c")
      assert nested_inner_1_c.op.name == "nested/inner_1/c"

      # Treats `scope` as an absolute name scope, and
      # switches to the "nested/" scope.
      with g.name_scope(scope):
        nested_d = tf.constant(40.0, name="d")
        assert nested_d.op.name == "nested/d"

        with g.name_scope(""):
          e = tf.constant(50.0, name="e")
          assert e.op.name == "e"
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

The name of the scope itself can be captured by with g.name_scope(…) as scope:, which stores the name of the scope in the variable scope. This value can be used to name an operation that represents the overall result of executing the ops in a scope. For example:

inputs = tf.constant(…) 
with g.name_scope(‘my_layer’) as scope: 
weights = tf.Variable(…, name=”weights”) 
biases = tf.Variable(…, name=”biases”) 
affine = tf.matmul(inputs, weights) + biases 
output = tf.nn.relu(affine, name=scope) 
NOTE: This constructor validates the given name. Valid scope names match one of the following regular expressions:

[A-Za-z0-9.][A-Za-z0-9_.\-/]* (for scopes at the root) 
[A-Za-z0-9_.\-/]* (for other scopes) 
Args:

name: A name for the scope. 
Returns:

A context manager that installs name as a new name scope.

Raises:

ValueError: If name is not a valid scope name, according to the rules above. 
prevent_feeding

二.Session(tf.Session)

运行TensorFLow操作(operations)的类,一个Seesion包含了操作对象执行的环境. 
一个例子:

# -*- coding: utf-8 -*- 

from __future__ import print_function,division
import tensorflow as tf

#build graph
a=tf.constant(2.)
b=tf.constant(5.)
c=a*b

#construct session
sess=tf.Session()

#Evaluate the tensor `c`
print(sess.run(c))

#close session
sess.close()
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

上面最后一句close()是因为session一般都拥有很多的资源,要是session不再可用的话,就要调用close()函数来释放这些资源。 
简单一点的话,也可以用上下文管理器,比如参照下面的方式:

# Using the `close()` method.
sess = tf.Session()
sess.run(...)
sess.close()

# Using the context manager.
with tf.Session() as sess:
  sess.run(...)
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

属性

graph:“投放”到session中的图 
graph_def:图的描述 
sess_str

重要函数:

tf.Session.__init__(target=”, graph=None, config=None)

作用: 
这是session的构造函数,创建一个新的tensorflow的session

参数: 
target:(可选)连接的执行引擎,默认是使用in-process引擎,分布式TensorFLow有更多的例子。 
graph: (可选)投放进的计算图(graph),要是没有指定的话,那么默认的图就会被投放到这个session。要是你在同一个进程里面用了很多的图,你将为各个图使用不用的session,但是每一个graph都能够在多个session中使用。在这种情况下,经常显式的传递graph参数到session的构造里面。 
config: (可选) A ConfigProto protocol buffer with configuration options for the session.

tf.Session.run(fetches, feed_dict=None, options=None, run_metadata=None)

作用: 
运行操作估算(计算)tensor。 
参数: 
fetches: 一个单独的图的元素,或者一个图的元素的列表。或者一个字典,这个字典的值是刚刚所说的一个图的元素(元素列表)(见下面第四部分的例子)。图的元素可以是一个操作(那么fetch回来的值将是None);一个tensor(反回的值将是将是表示这个tensor值的numpy ndarray对象);一个sparsetensor(稀疏tensor);一个get_tensor_handle的操作;一个表示tensor或者操作名称的string 
feed_dict: 一个字典,为之前“占位”的元素“喂”给值。(具体见第四部分的例子。) 
The optional feed_dict argument allows the caller to override the value of tensors in the graph. Each key in feed_dict can be one of the following types: 
If the key is a Tensor, the value may be a Python scalar, string, list, or numpy ndarray that can be converted to the same dtype as that tensor. Additionally, if the key is a placeholder, the shape of the value will be checked for compatibility with the placeholder. 
If the key is a SparseTensor, the value should be a SparseTensorValue. 
If the key is a nested tuple of Tensors or SparseTensors, the value should be a nested tuple with the same structure that maps to their corresponding values as above. 
Each value in feed_dict must be convertible to a numpy array of the dtype of the corresponding key. 
options: A [RunOptions] protocol buffer 
run_metadata: A [RunMetadata] protocol buffer 
返回值: 
如果你的fetchs参数传入的图的一个元素,那么返回一个单独的值,要是是图的一个元素列表,那么返回就是一个列表,要是你传入的是一个字典,那么返回的也是一个字典,这个字典的键和你传入的字典的键是一样的。函数返回的值和你传进去的fetch参数的形状是一样的,只是里面的元素是相应的值而已了。

The optional options argument expects a [RunOptions] proto. The options allow controlling the behavior of this particular step (e.g. turning tracing on).

The optional run_metadata argument expects a [RunMetadata] proto. When appropriate, the non-Tensor output of this step will be collected there. For example, when users turn on tracing in options, the profiled info will be collected into this argument and passed back.

Example:

   a = tf.constant([10, 20])
   b = tf.constant([1.0, 2.0])
   # 'fetches' can be a singleton
   v = session.run(a)
   # v is the numpy array [10, 20]
   # 'fetches' can be a list.
   v = session.run([a, b])
   # v a Python list with 2 numpy arrays: the numpy array [10, 20] and the
   # 1-D array [1.0, 2.0]
   # 'fetches' can be arbitrary lists, tuples, namedtuple, dicts:
   MyData = collections.namedtuple('MyData', ['a', 'b'])
   v = session.run({'k1': MyData(a, b), 'k2': [b, a]})
   # v is a dict with
   # v['k1'] is a MyData namedtuple with 'a' the numpy array [10, 20] and
   # 'b' the numpy array [1.0, 2.0]
   # v['k2'] is a list with the numpy array [1.0, 2.0] and the numpy array
   # [10, 20].
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

tf.Session.close()

作用:关闭这个session,调用这个函数会使得所有与这个session有关的资源被释放

as_default() 
作用:返回一个上下文管理器,使得这个对象成为当前默认的session/使用with关键字然后可以在with关键字代码块中执行tf.Operation.run和 tf.Tensor.eval ,都是默认在当前session下面执行。

c = tf.constant(..)
sess = tf.Session()

with sess.as_default():
  assert tf.get_default_session() is sess
  print(c.eval())
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
c = tf.constant(...)
sess = tf.Session()
with sess.as_default():
  print(c.eval())
# ...
with sess.as_default():
  print(c.eval())

Tensorflow之Graph和Session Tensorflow把计算的定义和执行很好的分离开来,使得整个模型跑起来仅需要两步: 第一步:描绘整幅图(定义计算) 第二步:在session当中执行图中的运算 在上幅图里: 节点: operators, variables, and constants 边: tensors 下面举几个具体实例来说明Graph和Session: import tensorflow as t 阅读详情

相关推荐

金仓数据库KCM认证考试介绍【2025年4月更新】

金仓数据库认证资深专家KCM认证考试介绍

qq709869231的博客 3238

NebulaGraph学习笔记-自定义SessionPool

【代码】NebulaGraph学习笔记-自定义SessionPool。

PURSUE ONE PIECE 524

ZYNQ开发(2)在Linux系统层上PL-PS通过AXI-DMA传输数据详细步骤及注意事项

参考的网络资料 https://github.com/bperez77/xilinx_axidma/tree/master https://gitlab.gnome.org/HosseinBeheshti/UlteraZed7EV/-/tree/master/petalinux/xilinx_axidma https://www.icode9.com/content-3-925319.html https://blog.youkuaiyun.com/weixin_38218267/article/details/1

aizaiyueye的专栏 3449

Tensorflow深度学习之三十四:tf.Graph.finalize()

一、tf.Graph.finalize() tf.Graph.finalize() # 有时候也可以使用下面的方式 # tf.get_default_graph().finalize()    Finalizes this graph, making it read-only.    结束当前的计算图,使之成为只读。    After calling g.finalize(), no new o...

DaVinciL的博客 4743

【故障处理】- ORA-01722

在执行升级脚本@?/rdbms/admin/catupgrd.sql时报错ora-01722。

weixin_39099660的博客 856

7 series FPGAs Transceiver Wizard IP核使用和测试

学习FPGA一段时间了,前面一直没有系统的总结,这学期把在项目中用到的IP核和一些调试过程中遇到的问题总结一下发出来,坚持下去,一起进步! 今天总结一下的GTH核的使用和测试。 软件版本:Vivado 2017.4 IP核版本:7 Series FPGAs Transceivers Wizard (3.6) FPGA:xc7vx690tfft1927 实现功能: 四路光纤数据接收,由于GTX IP...

qq_39921762的博客 1万+

tf.Graph

目录 1、__init__ 2、add_to_collection 3、add_to_collections 4、as_default 5、as_graph_def 6、as_graph_element 7、clear_collection 8、colocate_with 9、container 10、control_dependencies 11、create_op 12...

weixin_36670529的博客 1106

odoo19/18集成reportbro 打印插件 完美支持静默打印

ReportBro设计器 一个用于创建PDF和XLSX报告模板的javascript插件。ReportBro Designer可以轻松集成到您的Web应用程序中。每个人都可以设计和编辑文档模板,并直接在浏览器中预览它们。可以使用服务器上的 (有关完整的文档和演示,请参阅上的ReportBro项目网站。reportBro官方没有提供。测试环境:odoo17社区版。2.产品标签打印设计。

zxltwins的博客 2774

######(较深的应用)TensorFlow学习(三):Graph和Session ######(较深的应用)

之前讲完变量常量等等基本量的操作,意味着最基本的东西都有了,然后接下来很重要的就是那些量和操作怎么组成更大的集合,怎么运行这个集合。这些就是计算图谱graph和Session的作用了。 IV.Graph https://www.tensorflow.org/versions/r0.11/api_docs/python/framework.html#Graph 一个TensorFlow的运

木东的博客 4580

【LaTex】3.5 数据分析

简述了LaTex柱状图、饼图、折线图的画法。

你的指尖有改变世界的力量 5891

SKUA-GOCAD入门教程-第四节

本文介绍了软件界面中的几个关键功能模块。控制菜单允许用户通过按钮添加视图、对象窗口、工作流平台等工具到任务栏,并支持快速搜索。页面布局以任务为导向,包含3D、2D视图、工具栏等,用户可自定义页面和布局。对象窗口用于浏览和处理数据,如钻孔、断层等,支持显示、隐藏、分组和过滤数据。3D查看器的数据浏览器对象窗口包含列表、对象等,建模数据通常位于未分配对象窗口中。本文旨在帮助用户熟悉软件界面,特别是3D视图窗口和对象管理窗口,以便更高效地进行数据导入和建模操作。

江洋大葱的博客 1060

再看Tensorflow 里面的Graph 和Session

前言 今天深度学习课上老师着重讲了tensorflow里面的graph和Session的关系,这勾起了我的很多记忆,以前初学tensorflow的时候 那些概念都没有理解的很透彻,现在再来集中的总结一下。 Graph 在分布式系统中,人们经常使用计算图来表示并行计算模型。计算图是一个有向图,图里面有节点和有向边。在计算图里面,节点表示"计算"单元,有向边表示数据的流动关系或者依赖关系。 不过在te...

jmhIcoding 1346

记录:解决Ubuntu20.04安装ros报错E: Unable to locate package ros-kinetic-desktop-full【亲测有效】

报错:E: Unable to locate package ros-kinetic-desktop-full.尝试好久一直都无法下载,最后得知真相的我眼泪哗哗的直流。

**My Coding Family** 6万+

TENSORFLOW:GRAPH 和 SESSION

Graph 和 Session TensorFlow用数据流图来表示你的计算中的不同操作的依赖关系。这也导致在使用底层API进行编程的时候,你首先定义一个数据流图,然后创建一个session在一些本地或者远程的设备上运行定义的graph的各个部分。 如果你计划使用底层API进行编程,那么这个文档很有用。像Estimator还有Keras隐藏了很多关于graph和session的细节。但是如果你...

lcczzu的专栏 605

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

tensorflow 中的Graph 和 Session

本篇博客参考网址:https://www.cnblogs.com/jiaxblog/p/9054051.html(侵删) graph即tf.Graph(),session即tf.Session(),很多人经常将两者混淆,其实二者完全不是同一个东西。 graph定义了计算方式,是一些加减乘除等运算的组合,类似于一个函数。它本身不会进行任何计算,也不保存任何中间计算结果。 session用来运行一个g...

qq_29566629的博客 242

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

TensorFlow:graph、session和op

文章目录关于graph关于子图:subgraph关于session关于op一个特殊的op: tf.placeholder()global_step =tf.train.get_or_create_global_step()作用Reference graph即tf.Graph(),session即tf.Session(),很多人经常将两者混淆,其实二者完全不是同一个东西。 graph定义了计算方式,是一些加减乘除等运算的组合,类似于一个函数。它本身不会进行任何计算,也不保存任何中间计算结果。 session

m0_38024592的博客 578

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

tensorflow 中的 graph 和 Session

tensorflow 中的 graph一级目录二级目录三级目录 一级目录 二级目录 三级目录

GungnirsPledge的博客 762

tensorflow中graph、tensor、op和session等基本概念

tensor可以被简单的理解为多维数组,零阶表示标量、一阶表示向量、二阶表示二位数组。。。 但实际上,在tensorflow中,tensor本身不会存储具体数值,它只是对运算结果的引用,如: x1 = tf.constant(1.0, shape=[]) # 0D x2 = tf.constant(1.0, shape=[1]) # 1D x3 = tf.constant(1....

weixin_43750626的博客 3631

node-tensorflow核心三大件详解:Tensor、Graph与Session概念完全解析

node-tensorflow 是 Google 出品的 Node.js 模块,让你无需 Python 环境,直接用 JavaScript 加载 TensorFlow 计算图并完成模型推理。本文用最短的篇幅讲透它的三大核心概念:Tensor(张量)、Graph(计算图)与 Session(会话),帮你一次看懂 TensorFlow 的运行机制。 ## 一、node-tensorflow 是什么?

gitblog_00109的博客 408

Tensorflow Session graph Op 的理解

tensorflow graph session op tensor的理解

Searching_Bird的专栏 1078

Tensorflow加载多个模型方法实践——Graph与Session

Tensorflow加载多个模型方法是在Tensorflow中创建多个Session,每个Session运行一个graph。

肖永威的专栏 2779

TensorFlow中Graph和Session

Tensorflow中图谱Graph和Session的作用了。因为篇幅和格式的缘故,这里的测试代码并没写全,全部的代码可以在我的GitHub上面找到:LearningTensorFlow/3.Graph_and_Session/11一.Graph首先官方文档地址:tf.Graph 这里仅列出了最基本和频繁使用的函数,更多特定的需要请参考文档。Ⅰ.介绍一个TensorFlow的运算,被表示为一个数据...

WONITAWONITAWONITA的博客 384

详解Tensorflow中的图(tf.Graph)和会话(tf.Session)

Tensorflow编程系统 Tensorflow工具或者说深度学习本身就是一个连贯紧密的系统。一般的系统是一个自治独立的、能实现复杂功能的整体。系统的主要任务是对输入进行处理,以得到想要的输出结果。我们之前见过的很多系统都是线性的,就像汽车生产工厂的流水线一样,输入->系统处理->输出。系统内部由很多单一的基本部件构成,这些单一部件具有特定的功能,且需要稳定的特性;系统设计者通过特...

liqiang12689的博客 4178

TensorFlow-Course模型构建秘籍:Graph和Session深度解析

想要掌握TensorFlow的核心精髓?Graph和Session就是你必须深入理解的关键概念!🚀 在这篇终极指南中,我们将带你从零开始,完整解析TensorFlow计算图和会话的底层原理,让你真正成为TensorFlow大师。 TensorFlow 2.0虽然引入了即时执行模式,但在某些场景下,Graph模式仍然能够带来显著的性能提升。根据官方文档,计算图是包含tf.Operation对象(

gitblog_00102的博客 670
上一篇: TensorFlow学习(二):变量常量类型
下一篇: 下论文网址
github_zwl
博客等级 码龄11年 300粉丝 171原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值