python tensorflow tf.session类
@tf_export('Session')
class Session(BaseSession):"""A class for running TensorFlow operations. 用于运行TensorFlow操作的类。A `Session` object encapsulates the environment in which `Operation`objects are executed, and `Tensor` objects are evaluated. Forexample:“Session”对象封装了执行“操作”对象并评估“张量”对象的环境。 例如:
# Build a graph. 建立一个图
a = tf.constant(5.0)
b = tf.constant(6.0)
c = a * b# Launch the graph in a session. 在session中启动这个图。
sess = tf.Session()# Evaluate the tensor `c`. 评估张量c。
print(sess.run(c))
# 结果为30
A session may own resources, such as`tf.Variable`, `tf.QueueBase`,and `tf.ReaderBase`. It is important to releasethese resources when they are no longer required. To do this, eitherinvoke the `tf.Session.close` method on the session, or usethe session as a context manager. The following two examples areequivalent:session 可能拥有资源,例如“ tf.Variable”,“ tf.QueueBase”和“ tf.ReaderBase”。 当不再需要这些资源时,重要的是释放它们。 为此,请在会话上调用`tf.Session.close`方法,或将该会话用作上下文管理器。 以下两个示例是等效的:
# Using the `close()` method. 使用close()方法。
sess = tf.Session()
sess.run(...)
sess.close()# Using the context manager. 使用上下文管理器。
with tf.Session() as sess:sess.run(...)
The[`ConfigProto`](https://www.tensorflow.org/code/tensorflow/core/protobuf/config.proto)protocol buffer exposes various configuration options for asession. For example, to create a session that uses soft constraintsfor device placement, and log the resulting placement decisions,create a session as follows:[`ConfigProto`](https://www.tensorflow.org/code/tensorflow/core/protobuf/config.pr oto)协议缓冲区公开了会话的各种配置选项。
例如,要创建使用软约束进行设备放置的会话并记录生成的放置决策,请按以下方式创建会话:
# Launch the graph in a session that allows soft device placement and
# logs the placement decisions.
# 在允许软设备放置的会话中启动图形并记录放置决策。
sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True,log_device_placement=True))
def __init__(self, target='', graph=None, config=None):"""Creates a new TensorFlow session. 创建一个新的TensorFlow session。If no `graph` argument is specified when constructing the session,the default graph will be launched in the session. If you areusing more than one graph (created with `tf.Graph()` in the sameprocess, you will have to use different sessions for each graph,but each graph can be used in multiple sessions. In this case, itis often clearer to pass the graph to be launched explicitly tothe session constructor.如果在构建session时未指定`graph`参数,则默认图形将在session中启动。 如果您在同一过程中使用多个图(通过`tf.Graph()`创建的),则每个图必须使用不同的session,但是每个图可以用于多个session。在这种情况下, 通常更清楚地将要显式启动的图传递给会话构造函数。Args:target: (Optional. 可选的) The execution engine to connect to.Defaults to using an in-process engine. See[Distributed TensorFlow](https://tensorflow.org/deploy/distributed)for more examples.要连接的执行引擎。 默认为使用进程内引擎。 有关更多示例,请参见[Distributed TensorFlow](https://tensorflow.org/deploy/distributed)。graph: (Optional. 可选的) The `Graph` to be launched (described above).要启动的“图”(如上所述)。config: (Optional. 可选的) A[`ConfigProto`](https://www.tensorflow.org/code/tensorflow/core/protobuf/config.proto)protocol buffer with configuration options for the session.具有会话配置选项的[`ConfigProto`](https://www.tensorflow.org/code/tensorflow/core/protobuf/config.proto)协议缓冲区。"""super(Session, self).__init__(target, graph, config=config)# NOTE(mrry): Create these on first `__enter__` to avoid a reference cycle.# 在第一个__enter__上创建它们以避免引用循环。self._default_graph_context_manager = Noneself._default_session_context_manager = None
参考文章:tf.Session
python tensorflow tf.session类相关推荐
- python tensorflow tf.Session().run()函数(运行操作并评估“fetches”中的张量)
参考文章:TensorFlow-sess.run() 当我们构建完图(可能是我们pre_process后生成的图片?NoNoNo,它只是指tensorflow框架的一种设计理念--计算流图)后,需要在 ...
- Python之 使用session类模拟登陆人人网
使用request模块的session类模拟登陆人人网 因为人人网的登陆不需要验证码,故模拟登陆比较简单. 思路 1. 使用浏览器打开人人网的登陆页面 2. 找出登陆时发送post请求的url地址和请 ...
- python tensorflow tf.layers.max_pooling2d() 2维输入(例如图像)的最大池化层
from tensorflow\python\layers\pooling.py @tf_export('layers.max_pooling2d') def max_pooling2d(inputs ...
- 对比tensorflow查看打印输出张量Tensor的两种方法(急切执行tf.enable_eager_execution()和tf.Session.run())
第一种:tf.enable_eager_execution() # -*- coding: utf-8 -*- """ @File : 111.py @Time : 20 ...
- 支持向量机python代码_用TensorFlow实现多类支持向量机的示例代码
这篇文章主要介绍了用TensorFlow实现多类支持向量机的示例代码,现在分享给大家,也给大家做个参考.一起过来看看吧 本文将详细展示一个多类支持向量机分类器训练iris数据集来分类三种花. SVM算 ...
- tensorflow 启动Session(tf.Session(),tf.InteractivesSession(),tf.train.Supervisor().managed_session() )
(1)tf.Session() 计算图构造完成后, 才能启动图. 启动图的第一步是创建一个 Session 对象. 示例程序: #coding:utf-8 import tensorflow as t ...
- tensorflow 之tf.Session
样例代码 hello.py文件内容如下.这也是tensorflow入门级案例.其中创建了tf.Session. 本文分析一下session的相关代码及依赖. tensorflow安装在:envs/py ...
- tensorflow 无法执行sess =tf .session ()_深度学习|费解的tensorflow
学过Python的小伙伴都会觉得,python的语法简单,逻辑清晰.虽然tensorflow是python的一个库(并不是标准库),但是使用并不简单,你可能会被tensorflow的奇怪语法设计困惑, ...
- tensorflow tf.ConfigProto() (配置tf.Session的运算方式)(allow_soft_placement、inter_op_parallelism_threads等)
tf.ConfigProto()主要的作用是配置tf.Session的运算方式,比如gpu运算或者cpu运算 log_device_placement=True 设置tf.ConfigProto()中 ...
最新文章
- 杂题 NOIP2016蚯蚓
- CMD命令操作MySql数据库详解
- Nginx-05:Nginx配置实例之反向代理2
- Stanford UFLDL教程 池化Pooling
- 申请Let's Encrypt永久免费SSL证书
- android.net.wifi的简单使用方法
- 在sqlServer中把数据导出为insert脚本
- If you insist running as root, then set the environment variable RUN_AS_USER=root...
- mysql的分区技术
- pytorch双线性插值
- 离散傅里叶变换的核心公式
- 计算机开机只显示桌面不显示图标,电脑开机后只有桌面背景不显示图标怎么办...
- 【转载】CPU的内部架构和工作原理
- 数据库系统原理——实验一
- 2013武汉住房公积金新政详解
- 食物也疯狂!KOOCAN盘点因为食物毁掉的中国电视剧
- 专业办公套件(Office 2019)for Mac
- Onvif再学习---MiniXml-介绍
- leetcode 6 z字型变换
- vue中使用天地图测距、测面、标点【一】