tensorflow随笔-条件循环控制(1)
TensorFlow 提供了一些操作和類,您可以使用它們來控制操作的執行,并向圖表添加條件依賴項。
tf.identity
tf.tuple
tf.group
tf.no_op
tf.count_up_to
tf.cond
tf.case
tf.while_loop
tf.identity
tf.identity(
input,
name=None
)
返回和輸入大小與內容一致的tensor
參數:
input: 一個Tensor.
name: 操作名字(可選)
這個方法的源碼:
從源碼可看出,input的device會與context.context()相比較,如果相同,則直接返回input,如果不相同則返回disable=protected-access權限的input的copy。
#!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Mon Aug 27 11:16:32 2018"""import tensorflow as tf x1 = tf.constant(2.) x2 = [1,2,3] y1=tf.identity(x1,name="my_y1") y2=tf.identity(x2,name="my_y") sess=tf.Session() with sess: print sess.run(y1)print sess.run(y2)2.0
[1 2 3]
tf.tuple(元組)
tf.tuple(
tensors,
name=None,
control_inputs=None
)
將多個tensor合并組。
這創建了一個張量元組,其值與多張量參數相同,只是每個張量的值只有在計算完所有張量的值之后才返回。
control_inputs包含額外的OPS,在OP完成之前必須完成,但其輸出不返回。
這可以被用作并行計算的“連接”機制:所有的參數張量可以并行計算,但是在所有并行計算完成之后,元組返回的任何張量的值都是可用的。
.
參數:
tensors: 多tensor的列表或IndexedSlices, 有些條目可能是None。
name: (可選)用作操作的 name_scope的名稱。
control_inputs: 在返回之前完成附加操作表
返回:
像tensors一樣
Raises:
ValueError:如果tensors沒有包括任何tensor或IndexedSlices。
TypeError: 如果control_inputs不是一個Operation或Tensor 對象的列表。
[[ 9.989998 9.980425 9.897268 … 10.010141 10.008263 10.005144]
[ 9.970587 9.988404 10.011098 … 10.027785 9.956984 10.110886]
[ 9.982615 9.952952 10.033136 … 9.999784 10.009718 9.915539]
…
[ 9.934934 9.926054 10.045075 … 10.0579 10.020126 9.959899]
[10.031994 10.059689 10.05442 … 10.009988 9.977903 10.036525]
[ 9.945853 9.955557 10.047363 … 10.067215 9.942139 10.06124 ]]
總結
以上是生活随笔為你收集整理的tensorflow随笔-条件循环控制(1)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php并发取源码,PHP读取大文件源码示
- 下一篇: vue-cli搭建和“Cannot fi