strided_slice

    strided_slice算子。

    该OP沿多个轴生成 input 的切片,与numpy类似: 。该OP使用 axesstartsends 属性来指定轴列表中每个轴的起点和终点位置,并使用此信息来对 input 切片。如果向 startsends 传递负值如

    ,则表示该轴的反向第

    strided_slice - 图1

    参数:

    返回:多维 或 LoDTensor,数据类型与 input 相同。

    返回类型:Variable。

    抛出异常:

    • TypeErrorstarts 的类型应该是 list、tuple 或 Variable。

    • TypeErrorends 的类型应该是 list、tuple 或 Variable。

    代码示例:

    1. import paddle.fluid as fluid
    2. input = fluid.layers.data(
    3. name="input", shape=[3, 4, 5, 6], dtype='float32', append_batch_size=False)
    4. # example 1:
    5. # attr starts is a list which doesn't contain tensor Variable.
    6. axes = [1, 2, 3]
    7. starts = [-3, 0, 2]
    8. strides_1 = [1, 1, 1]
    9. strides_2 = [1, 1, 2]
    10. sliced_1 = fluid.layers.strided_slice(input, axes=axes, starts=starts, ends=ends, strides=strides_1)
    11. # sliced_1 is input[:, 0:3:1, 0:2:1, 2:4:1].
    12. # example 2:
    13. # attr starts is a list which contain tensor Variable.
    14. minus_3 = fluid.layers.fill_constant([1], "int32", -3)
    15. # sliced_2 is input[:, 0:3:1, 0:2:1, 2:4:2].