tf.control_dependencies与tf.identity组合详解
来源:互联网 发布:免费网络加速器 编辑:程序博客网 时间:2024/05/01 15:10
参考链接:
http://blog.csdn.net/m0_37041325/article/details/76943364
https://stackoverflow.com/questions/34877523/in-tensorflow-what-is-tf-identity-used-for
tf.control_dependencies(self, control_inputs)
arguments:control_inputs: A list of `Operation` or `Tensor` objects which must be executed or computed before running the operations defined in the context. (注意这里control_inputs是list)
return: A context manager that specifies control dependencies for all operations constructed within the context.(返回所有在环境中的控制依赖的上下文管理器)
该方法可以控制操作(op)执行的顺序,不能为tensor
tf.identity(input, name=None)
Args:
input: A Tensor.
name: A name for the operation (optional).
Returns:A tensor with the same shape and contents as the input tensor or value.
源于StackOverFlow有个关于两者使用的例子:
x = tf.Variable(0.0)x_plus_1 = tf.assign_add(x, 1)with tf.control_dependencies([x_plus_1]): y = xinit = tf.global_variables_initializer()with tf.Session() as session: init.run() for i in range(5): print(y.eval())
输出变量x,结果也为0.0
说明x_plus_1操作并没有被执行,我认为虽然tf.control_dependencies参数中的op列表会在with包含的操作op执行之前先执行,但是y=x这个语句并不是一个op,而是一个tensor,所以执行y=x时,并不会执行tf.control_dependencies参数中的操作op。
所以可以将 y=x 修改为 y=tf.identity(x),此时这个语句就是一个操作op,要先执行tf.control_dependencies参数中的op列表,再执行y=tf.identity(x)操作,最终输出结果为1.0 2.0 3.0 4.0 5.0,最终变量x的结果也为5.0,完整程序如下:
x = tf.Variable(0.0)x_plus_1 = tf.assign_add(x, 1)with tf.control_dependencies([x_plus_1]): y = tf.identity(x)init = tf.global_variables_initializer()with tf.Session() as session: init.run() for i in range(5): print(y.eval()) print(x.eval())
- tf.control_dependencies与tf.identity组合详解
- tf.control_dependencies()和tf.identity()
- tf.control_dependencies()
- tf.cond 与 tf.control_dependencies 的控制问题
- tensorflow API:tf.control_dependencies
- tf.control_dependencies()作用及用法
- tf.identity()的理解
- tf.identity的作用
- TF
- tf
- tf.truncated_normal与tf.random_normal
- tf.InteractiveSession()与tf.Session()
- tf.reduce_mean与tf.reduce_min
- tf.shape()与tf.get_shape()
- tensorflow学习——tf.get_collection(), tf.identity()
- tf.identity的意义以及用例
- tf.Variable()与tf.get_variable()与不同之处
- tf-idf详解
- Maven 使用帮助
- 【使用Postman测试WEB接口】执行测试
- 集成NVM的超低功耗2.4GHz GFSK/FSK无线发射芯片SI24R2E
- Lucene的索引文件锁原理
- Groovy基础
- tf.control_dependencies与tf.identity组合详解
- 深度学习引论(三):损失函数、BP算法
- EastUi验证
- IC卡读写
- struts2-15自定义拦截器
- C# 调用 WebServices 接口
- Ubuntu发布重要更新将修复九个漏洞
- PMBOK笔记 第1章 引论 (2)
- CTS测试框架 -- 基础框架启动