tf.nn.l2_normalize.md 846 字节
Newer Older
J
jiangjiajun 已提交
1 2
## tf.nn.l2_normalize

J
jiangjiajun 已提交
3
### [tf.nn.l2_normalize](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/l2_normalize)
J
jiangjiajun 已提交
4 5 6 7 8 9 10 11 12 13 14

```python
tf.math.l2_normalize(
    x,
    axis=None,
    epsilon=1e-12,
    name=None,
    dim=None
)
```

J
jiangjiajun 已提交
15
### [paddle.fluid.layers.l2_normalize](http://paddlepaddle.org/documentation/docs/zh/1.4/api_cn/layers_cn.html#l2-normalize)
J
jiangjiajun 已提交
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

```python
paddle.fluid.layers.l2_normalize(
    x, 
    axis, 
    epsilon=1e-12, 
    name=None
)
```

### 功能差异

#### 计算方式

TensorFlow:计算方式为`output = x / sqrt(max(sum(x^2), epsilon))`;  
PaddlePaddle:计算方式为`output = x / sqrt(sum(x^2) + epsilon))`


### 代码示例
```
# x是shape为[3,2]的张量

# out同样是shape[3,2]的张量,axis设置为1,表示将x中每个行向量做归一化
out = fluid.layers.l2_normalize(x, axis=1)
J
jiangjiajun 已提交
40
```