源代码积少成多

本文介绍TensorFlow中关键的操作,包括如何使用convert_to_tensor转换数据类型,name_scope命名空间的应用,以及通过control_dependencies实现依赖操作。同时,还探讨了条件判断与断言(assert)的实现方式。

ops

convert_to_tensor

name_scope

def my_op(a, b, c, name=None):
    with tf.name_scope(name, "MyOp", [a, b, c]) as scope:
      a = tf.convert_to_tensor(a, name="a")
      b = tf.convert_to_tensor(b, name="b")
      c = tf.convert_to_tensor(c, name="c")
      # Define some computation that uses `a`, `b`, and `c`.
      return foo_op(..., name=scope)

control_dependencies

这个目前发现的是和control_flow_ops.Assert连用,可以看下面Assert的实例

math_ops

greater

大于的显示true,支持broadcast

array_ops

size

# 't' is [[[1, 1, 1], [2, 2, 2]], [[3, 3, 3], [4, 4, 4]]]]
size(t) ==> 12

gen_array_ops

identity

Return a tensor with the same shape and contents as the input tensor or value

gen_image_ops

Decode a JPEG-encoded image to a uint8 tensor

control_flow_ops

Assert

Asserts that the given condition is true

 # Ensure maximum element of x is smaller or equal to 1
  assert_op = tf.Assert(tf.less_equal(tf.reduce_max(x), 1.), [x])
  x = tf.with_dependencies([assert_op], x)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值