tf.nn.lrn.md 1.0 KB
Newer Older
J
Jason 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

## tf.nn.lrn

### [tf.nn.lrn](https://www.tensorflow.org/api_docs/python/tf/nn/local_response_normalization)

```python
tf.nn.local_response_normalization(
    input,
    depth_radius=5,
    bias=1,
    alpha=1,
    beta=0.5,
    name=None
)
```

### [paddle.fluid.layers.lrn](http://paddlepaddle.org/documentation/docs/zh/1.3/api_cn/layers_cn.html#paddle.fluid.layers.lrn)

```python
paddle.fluid.layers.lrn(
    input, 
    n=5, 
    k=1.0, 
    alpha=0.0001, 
    beta=0.75, 
    name=None
)
```

### 功能差异

#### 计算方式

TensorFlow:计算公式如下所示,
J
Jason 已提交
35
$$output(i,x,y)=input(i,x,y)/(k+\alpha\sum_{j=max(0,i-n)}^{min(C,i+n+1)}{input(j,x,y)^2})^\beta$$ 
J
Jason 已提交
36
PaddlePaddle:计算公式如下所示,
J
Jason 已提交
37
$$output(i,x,y)=input(i,x,y)/(k+\alpha\sum_{j=max(0,i-\frac{n}{2})}^{min(C,i+\frac{n}{2})}{input(j,x,y)^2})^\beta$$ 
J
Jason 已提交
38 39 40 41 42 43 44 45 46


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

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