tensorflow - 理解 tf.cond 的图
问题描述
我试图通过查看用于构建它的低级操作图来了解 tf.cond 的内部工作原理。
这是有问题的代码
x = tf.constant(1, name='x')
y = tf.constant(2, name='y')
z = tf.constant(3, name='z')
result = tf.cond(tf.less(x, y), lambda: tf.add(x, z), lambda: tf.square(y))
和结果图。
我想知道的是以下内容。
- 导致 switch_t 和 switch_f 的单独开关操作是什么?
- 为什么 Less 输出连接到 pred_id 和 Switch Ops?我希望它为所有输入到 tf.cond 的所有 Switch 输出一个谓词(布尔张量)。
- pred_id 是什么?只是一个身份将谓词分成三个分支吗?
我试图了解 tf.cond 在运行时如何只评估一个分支。
我知道当我们评估 tf.cond 的结果时,我们正在评估来自合并操作的张量。Merge 必须接受(我假设)四个张量作为输入(两个来自 Add 分支,两个来自 Square 分支),其中三个是死的。但是,如果我们在图表中评估它们,我们只能知道张量的“死亡”,不是吗?
例如,对于 Square 分支,我知道 switch 将 y 张量和谓词作为输入,并在 switch 语句的适当分支上输出两个张量 y 和 dead。但是这个分支可以保证已经是错误的分支。那么开关支路的 T 和 F 输出会发生什么变化呢?他们都进入Square Op?然后进入合并?
谢谢,
小号
解决方案
推荐阅读
- javascript - 如何防止 jquery 提交按钮刷新 HTML 页面?
- javascript - Selenium webdriver - 页面结束(使用垂直滚动)
- angular - APP_INITIALIZE 后初始化模块
- android - 无法在 android 设备的省电模式下以编程方式检查网络信息
- xcode - Swift 4 隐藏视图并填补空白
- django - 如何在字典中保存元素倍数?
- node.js - 运行 `npm install xx`, `npm uninstall xx` 后,npm 如何知道如何更新 `package.json`
- ruby-on-rails - 将默认时间格式设为 ISO8601
- ios - 尝试读取 txt 文件时出现 TIC SSL 信任错误
- javascript - gridstack.js 根据内部内容设置 grid-stack-item 高度自动