5、TensorFLow 控制流

来源:互联网 发布:有韵味的句子知乎 编辑:程序博客网 时间:2024/06/05 16:43

一、Control Flow Operations

# 先占个坑, 有空来补...tf.group(*inputs, **kwargs)tf.tupletf.identitytf.no_optf.count_up_totf.condtf.casetf.while_loop

二、Logical Operators

# 逐元素的进行与/或/非/异或运算,每个元素的 dtype 必须为 bool 型,返回真值表  tf.logical_and(x, y, name=None)tf.logical_or(x, y, name=None)tf.logical_not(x, name=None)tf.logical_xor(x, y, name=None)

三、Comparison Operators

# 逐元素的进行== != > >= < <=比较,返回真值表(True/False)# x 和 y 的数据类型必须一致, 形状不必一致,支持 broadcastingtf.equal(x, y, name=None)tf.not_equal(x, y, name=None)tf.greater(x, y, name=None)tf.greater_equal(x, y, name=None)tf.less(x, y, name=None)tf.less_equal(x, y, name=None)# x if condition else y, condition 为 bool 类型的,可用tf.equal()等来表示# x 和 y 的形状和数据类型必须一致tf.where(condition, x=None, y=None, name=None)

四、Debugging Operations

# 判断 x 是否是有穷、无穷、NAN, 返回逐元素的判断结果,x 必须为浮点型tf.is_finite(x, name=None)tf.is_inf(x, name=None)tf.is_nan(x, name=None)# Assert that the tensor does not contain any NaN's or Inf's# True 的话,返回 t 执行后的值;False 的话,输出失败的 msgtf.verify_tensor_all_finite(t, msg, name=None)tf.Print(input_, data, message=None, first_n=None, summarize=None, name=None)Args:input_: A tensor passed through this opdata: A list of tensors to print out(log) when input_ op is evaluatedmessage: data 的前缀,是一个stringfirst_n: 只记录 first_n 次. 为负数的话就一直记录(缺省值)summarize: 对每个 tensor 打印的条目数量。如果是 None,对于每个输入tensor只打印 3 个元素Returns: input_ 的运行结果# If condition evaluates to false, print the list of tensors in data. summarize determines how many entries of the tensors to print.tf.Assert(condition, data, summarize=None, name=None)Args:condition: The condition to evaluate.data: The tensors to print out when condition is false.summarize: Print this many entries of each tensor.name: A name for this operation (optional).Returns:assert_op: An Operation that, when executed, raises a tf.errors.InvalidArgumentError if condition is not true.

五、参考资料

1、https://www.tensorflow.org/api_guides/python/control_flow_ops
2、Tensorflow之调试(Debug)及打印变量