Slice.md 1.4 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
## Slice


### [Slice](http://caffe.berkeleyvision.org/tutorial/layers/slice.html)
```
layer {
    name: "slice"
    type: "Slice"
    bottom: "data"
    top: "out1"
    top: "out2"
    top: "out3"
    slice_param{
	axis: 1
	alice_point: 1
	alice_point: 2
	# slice_dim: 1
    }
}
```


### [paddle.fluid.layers.slice](http://paddlepaddle.org/documentation/docs/zh/1.3/api_cn/layers_cn.html#permalink-160-slice)
```python
paddle.fluid.layers.slice(
    input, 
    axes, 
    starts, 
    ends
)
```  

### 功能差异
J
Jason 已提交
34 35 36 37
#### slice机制
Caffe:`axis``alice_point`参数为数值,只能在一个维度上截取,但可以截取多个切片;            
PaddlePaddle:`axes``start``ends`参数为`list`类型,可以在多个维度上截取,但只能截取一个切片。

S
sunyanfang01 已提交
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
### 代码示例
```  
# Caffe示例:  
# 输入shape:(2,6)
layer {
    name: "slice"
    type: "Slice"
    bottom: "data"
    top: "out1"
    top: "out2"
    top: "out3"
    slice_param{
	axis: 1	#使用-1效果相同
	alice_point: 1
	alice_point: 2
    }
}
# 输出3个数组,第一个shape:(2,1),第二个shape:(2,1),第三个shape:(2,4)
```  
```python
# PaddlePaddle示例:  
# 输入shape:(2,6)
output1 = paddle.fluid.layers.slice(input = inputs, axes = [1], starts= [1], ends = [3])
# 输出shape:(2,2)
output2 = paddle.fluid.layers.slice(input = inputs, axes = [0,1], starts= [0,1], ends = [1,3])
# 输出shape:(1,2)
```