python - 无法使用 tf.control_dependencies() 创建控制依赖项
问题描述
我试图理解tf.control_dependencies()
,并想验证它确实创建了控制依赖项。这是代码
import tensorflow as tf
a = tf.get_variable('a', shape = [2, 3])
b = tf.get_variable('b', shape = [2, 3])
c = tf.scalar_mul(2, a)
d = tf.scalar_mul(3, b)
with tf.control_dependencies([d, c]):
f = d-c
print (f.op.control_inputs)
它返回[]
了,这不是我所期望的。如果我按以下方式添加控制依赖项
f = d-c
f.op._add_control_inputs([c.op, d.op])
print (f.op.control_inputs)
它回馈了我的预期[<tf.Operation 'Mul' type=Mul>, <tf.Operation 'Mul_1' type=Mul>]
。
所以我的问题是,tf.control_dependencies()
真的添加控制依赖项吗?还是f.op.control_inputs
返回所有控制输入?
解决方案
在这里解决了。只是更改tf.get_variable()
为tf.Varibble()
.
推荐阅读
- c# - How to populate objects with relationship from datatable?
- sqlite - SQLiteStudio 自动插入值
- tensorflow - Tensorflow Keras Conv2D 多个过滤器
- amazon-web-services - 是否有任何命令可以使用 AWS SAM CLI 在本地以“调试”模式运行 Lambda 函数?
- swift - 从 Xcode 中的 swift 文件打开 Unix 可执行文件(和授权)
- c# - 不在 AddressFamily InterNetwork 中的 IPAddress 示例
- java - 如何使用 micronaut http 客户端进行摘要身份验证?
- python - 从批处理文件启动的控制台窗口不显示整个过程
- r - 如何在echarts4r中指定轴值的顺序
- flutter - 如何在没有小括号的Dart中访问List中Map的特定索引的键和值?