- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我试图了解使用 tf.Session
和 tf.train.MonitoredTrainingSession
之间的区别,以及我可能更喜欢其中一个。似乎当我使用后者时,我可以避免许多“琐事”,例如初始化变量、启动队列运行器或设置文件编写器以进行汇总操作。另一方面,在受监控的培训类(class)中,我无法明确指定要使用的计算图。这一切对我来说似乎相当神秘。这些类的创建方式背后是否有一些我不理解的基本哲学?
最佳答案
我无法就这些类的创建方式提供一些见解,但这里有一些我认为与您如何使用它们相关的事情。
tf.Session
是 python TensorFlow API 中的一个低级对象,而,正如您所说,tf.train.MonitoredTrainingSession
具有许多方便的功能,在大多数常见情况下尤其有用。
在描述 tf.train.MonitoredTrainingSession
的一些好处之前,让我回答一下关于 session 使用的图表的问题。您可以通过使用上下文管理器 with your_graph.as_default()
来指定 MonitoredTrainingSession
使用的 tf.Graph
:
from __future__ import print_function
import tensorflow as tf
def example():
g1 = tf.Graph()
with g1.as_default():
# Define operations and tensors in `g`.
c1 = tf.constant(42)
assert c1.graph is g1
g2 = tf.Graph()
with g2.as_default():
# Define operations and tensors in `g`.
c2 = tf.constant(3.14)
assert c2.graph is g2
# MonitoredTrainingSession example
with g1.as_default():
with tf.train.MonitoredTrainingSession() as sess:
print(c1.eval(session=sess))
# Next line raises
# ValueError: Cannot use the given session to evaluate tensor:
# the tensor's graph is different from the session's graph.
try:
print(c2.eval(session=sess))
except ValueError as e:
print(e)
# Session example
with tf.Session(graph=g2) as sess:
print(c2.eval(session=sess))
# Next line raises
# ValueError: Cannot use the given session to evaluate tensor:
# the tensor's graph is different from the session's graph.
try:
print(c1.eval(session=sess))
except ValueError as e:
print(e)
if __name__ == '__main__':
example()
所以,正如你所说,使用 MonitoredTrainingSession
的好处是,这个对象负责
但它还具有使您的代码易于分发的好处,因为它的工作方式也不同,具体取决于您是否将正在运行的进程指定为主进程。
例如,您可以运行类似:
def run_my_model(train_op, session_args):
with tf.train.MonitoredTrainingSession(**session_args) as sess:
sess.run(train_op)
您将以非分布式方式调用:
run_my_model(train_op, {})`
或以分布式方式(有关输入的更多信息,请参阅 distributed doc):
run_my_model(train_op, {"master": server.target,
"is_chief": (FLAGS.task_index == 0)})
另一方面,使用原始 tf.Session
对象的好处是,您没有 tf.train.MonitoredTrainingSession
的额外好处,如果您不打算使用它们或想要获得更多控制权(例如队列的启动方式),这可能会很有用。
编辑(根据评论):对于操作初始化,您必须执行类似 (cf. official doc :
# Define your graph and your ops
init_op = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init_p)
sess.run(your_graph_ops,...)
对于 QueueRunner,我建议您引用 official doc您可以在其中找到更完整的示例。
EDIT2:
了解 tf.train.MonitoredTrainingSession
工作原理的主要概念是 _WrappedSession
类:
This wrapper is used as a base class for various session wrappers that provide additional functionality such as monitoring, coordination, and recovery.
tf.train.MonitoredTrainingSession
以这种方式工作(从 version 1.1 开始):
StopAtStepHook
在这个阶段只会检索 global_step
张量。Chief
(或 Worker
session ),该 session 被包装在一个 _HookedSession
中,该 _CoordinatedSession
包装在一个 _CoordinatedSession
包装成 _RecoverableSession
。Chief
/Worker
session 负责运行 Scaffold
提供的初始化操作。
scaffold: A `Scaffold` used for gathering or building supportive ops. If
not specified a default one is created. It's used to finalize the graph.
chief
session 还负责所有检查点部分:例如使用 Scaffold
中的 Saver
从检查点恢复。_HookedSession
基本上是用来装饰 run
方法的:它调用 _call_hook_before_run
和 after_run
方法时相关的。 _CoordinatedSession
会构建一个 Coordinator
,它会启动队列运行器并负责关闭它们。_RecoverableSession
将确保在 tf.errors.AbortedError
的情况下重试。总之,tf.train.MonitoredTrainingSession
避免了很多样板代码,同时可以通过钩子(Hook)机制轻松扩展。
关于python - 受监控的培训类(class)如何运作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43245231/
我已经在 ubuntu 14.0 上成功安装了 Zabbix 3.2 服务器主机上的 Z 是绿色的。不幸的是,JMX 是红色的。 Zabbix 服务器:192.168.1.112 带有 tomcat
我想制作一个仪表板,显示我们的 Azure 服务总线队列的状态,并显示“添加到队列的消息”、“队列长度”和“已处理的消息”等的历史记录。使用 Azure 管理门户,我可以看到,这些统计信息大部分是手动
我的 MYSQL 每天晚上都有事件,但我不太确定发生了什么,因为即使我将其设置得早于其他事件,它仍然在早上运行。 问题是,我如何检查运行事件的历史记录或日志,哪一个晚上锁了,哪一个是跑了没跑? 谢谢
1、监控log文件大小超过10g的server 和db 复制代码代码如下: create procedure db_sendmail_mssqllogsize as&n
本教程讨论如何使用 AspectJ 开源框架监控 Spring 应用程序在方法执行方面的性能。 传统上,监控每个 Java 方法所花费的时间的最简单方法是在方法的开头和结尾包含一些跟踪行: publi
有什么可以帮助 msmq 监控的吗?当消息出现在队列中并且在休假时相同时,我想获得一些事件/监视器。 最佳答案 查看 Windows 管理性能计数器。 如果您查看管理工具并找到“性能计数器”,您将能够
我的 Tomcat 中的一个巨大的 web 应用程序有时会开始使用过多的 DBCP 连接,从而导致问题。 为了进行调查,我想在每个时间点准确地知道什么线程/方法持有池的连接。不需要是实时的,事后分析就
在浏览器的整个页面生命周期中监视 cookie 并在 cookie 更改时触发事件的最佳 JS 或 JQuery 特定方法是什么? 最佳答案 据我所知,不可能将 change (或类似)事件直接绑定(
我想尽可能详细地报告我的笔记本的执行情况。简而言之,我想实时查看我的笔记本正在执行的每个操作。例如,我的一个函数有一个 sleep 周期为 5 秒的循环,我希望看到程序实际上正在 sleep 并且循环
Azure 容器服务是否与 Azure Monitor 集成?想知道对 kubernetes 集群进行日志记录/监控的最佳方法是什么? 最佳答案 如果您正在 Azure 上寻找监视工具,您可能需要使用
我一直在尝试使用 erlang:monitor/2 来监视 gen_server。不幸的是,每次我尝试这个时,Erlang shell 都会进入无限循环。 这是我为测试这一点而编写的测试程序。 -mo
Azure 容器服务是否与 Azure Monitor 集成?想知道对 kubernetes 集群进行日志记录/监控的最佳方法是什么? 最佳答案 如果您正在 Azure 上寻找监视工具,您可能需要使用
我想使用 编写一个 shell 脚本来监控集群中的消费者滞后 bin/kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --zkconnect
在 .NET 中,假设 thread A 锁定了一个对象。同时,线程B和线程C被阻塞,等待线程A解锁对象。 现在,线程 A 解锁了对象。接下来将选择哪个线程(B 或 C)?它是如何确定的? 最佳答案
我搜索过这个主题,但发现很少有有用的细节。有了这些细节,我尝试编写一些代码如下。 注意:在将此帖子标记为重复之前,请将此帖子中共享的详细信息与其他帖子进行比较,而不仅仅是按主题。 - (NSArray
目录 1、指标监控 2、常用的监控端点 3、定制EndPoint 4、spring boot admin(可以使用)
我们使用 Prometheus 和 Grafana 来监控我们的 Kafka 集群。 在我们的应用程序中,我们使用 Kafka 流,Kafka 流有可能因异常而停止。我们正在记录事件 setUnCau
我正在建立一个复杂的网络仿真,并试图捕捉一些重要的性能测量。 我在服务器上运行了 mininet,并且我将视频从一个 mininet 主机流式传输到另一个(使用 -nodisp 选项,因为我没有 GU
Jenkins 的 openstack-plugin 使用 openstack4j 与 openstack 云对话。我正在寻找一种方法,我们可以从客户端的角度监控 openstack4j 所做的 ht
我正在处理一项需要监控 Thunderbolt 端口连接变化的要求。 (当连接或断开 Thunderbolt 电缆时)。 我尝试使用 IOServiceMatching(kIOUSBInterface
我是一名优秀的程序员,十分优秀!