normalization.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:tflearn 作者: tflearn 项目源码 文件源码
def l2_normalize(incoming, dim, epsilon=1e-12, name="l2_normalize"):
    """ L2 Normalization.

    Normalizes along dimension `dim` using an L2 norm.

    For a 1-D tensor with `dim = 0`, computes
output = x / sqrt(max(sum(x**2), epsilon))
```

For `x` with more dimensions, independently normalizes each 1-D slice along
dimension `dim`.

Arguments:
    incoming: `Tensor`. Incoming Tensor.
    dim: `int`. Dimension along which to normalize.
    epsilon: `float`. A lower bound value for the norm. Will use
        `sqrt(epsilon)` as the divisor if `norm < sqrt(epsilon)`.
    name: `str`. A name for this layer (optional).

Returns:
  A `Tensor` with the same shape as `x`.
"""
with tf.name_scope(name) as name:
    x = tf.convert_to_tensor(incoming, name="x")
    square_sum = tf.reduce_sum(tf.square(x), [dim], keep_dims=True)
    x_inv_norm = tf.rsqrt(tf.maximum(square_sum, epsilon))

return tf.multiply(x, x_inv_norm, name=name)

```

评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号