Pooling.md 1.9 KB
Newer Older
S
sunyanfang01 已提交
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
## Pooling

### [Pooling](http://caffe.berkeleyvision.org/tutorial/layers/pooling.html)
```
layer{
    name: "pool"
    type: "Pooling"
    bottom: "conv"
    top: "pool"
    pooling_param{
	pool: MAX
	kernel_size: 3	#必填项
	stride: 1
	pad: 0
    }
}
```
### [paddle.fluid.layers.pool2d](http://paddlepaddle.org/documentation/docs/zh/1.3/api_cn/layers_cn.html#permalink-115-pool2d)
```python
paddle.fluid.layers.pool2d(
    input,
    pool_size,
    pool_type = 'max',
    pool_stride = 1,
    pool_padding = 0,
    global_pooling = False,
    use_cudnn = True,
    ceil_mode = False,
    name = None,
    exclusive = True
)
```  
  
### 功能差异
J
Jason 已提交
35
#### 输出大小 
J
Jason 已提交
36 37 38 39 40
Caffe:输出大小计算方式如下所示,
```
H_out = (H_in-ksize[0]+2*padding[0])/strides[0]+1
W_out = (W_in-ksize[1]+2*padding[1])/strides[1]+1
```
S
sunyanfang01 已提交
41

J
Jason 已提交
42 43 44 45 46 47
PaddlePaddle:`ceil_mode``Ture`时,输出大小计算方式与Caffe一致;当`ceil_mode``False`时,输出大小计算方式如下所示,
```
# ceil_model为False时,计算公式
H_out = (H_in-ksize[0]+2*padding[0]+strides[0]-1)/strides[0]+1
W_out = (W_in-ksize[1]+2*padding[1]+strides[1]-1)/strides[1]+1
```
S
sunyanfang01 已提交
48

J
Jason 已提交
49 50 51
#### 池化方式
Caffe:通过`pool`参数设置,支持`MAX`, `AVE``STOCHASTIC`三种池化方式;  
PaddlePaddle:通过`pool_type`参数设置,支持`max``avg`两种池化方式。
S
sunyanfang01 已提交
52

J
Jason 已提交
53 54 55
#### 其他 
Caffe:无`exclusive`参数;  
PaddlePaddle:`exclusive`参数为`True`的情况下,`avg`平均池化过程中会忽略填充值。
S
sunyanfang01 已提交
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87


### 代码示例

```  
# Caffe示例:  
# 输入shape:(1,3,228,228)  
# 输出shape:(1,3,114,114)
layer{
    name: "pool"
    type: "Pooling"
    bottom: "conv"
    top: "pool"
    pooling_param{
	pool: MAX
	kernel_size: 3	
	stride: 2
    }
}
```  
``` python
# PaddlePaddle示例:  
# 输入shape:(1,3,228,228)  
# 输出shape:(1,3,113,113)
pool1 = paddle.fluid.layers.pool2d(input = inputs , pool_size = 3, pool_type = 'max', pool_stride = 2, ceil_mode=False)
```