What does `tf.strided_slice()` do?

前端 未结 5 1887
隐瞒了意图╮
隐瞒了意图╮ 2020-12-29 05:24

I am wondering what tf.strided_slice() operator actually does.
The doc says,

To a first order, this operation extracts a slice of siz

5条回答
  •  我在风中等你
    2020-12-29 06:24

    I find this technique useful to debug the solution. rule: always omit recurring patterns and try to keep step at (end-1).

    t = tf.constant([[[1, 1, 1], [2, 2, 2]],
                 [[3, 3, 3], [4, 4, 4]],
                 [[5, 5, 5], [6, 6, 6]]])  
    
    # ex 1:
    tf.strided_slice(t, [1, 0, 0], [2, 1, 3], [1, 1, 1])
    
    # 3rd position:
    1,0,0 > 3     
    1,0,1 > 3
    1,0,2 > 3
    # 2nd and 1st position:satisfies the rule listed above, skipping these.
    
    # ex 2:
    tf.strided_slice(t, [1, 0, 0], [2, 2, 3], [1, 1, 1])
    
    # 3rd position:
    1,0,0 > 3     
    1,0,1 > 3
    1,0,2 > 3
    # 2nd positon:
    1,1,0 > 4
    1,1,1 > 4
    1,1,2 > 4
    # 1st position: satisfies the rule listed above, skipping.
    
    # Ex 3:
    tf.strided_slice(t, [1, -1, 0], [2, -3, 3], [1, -1, 1])
    
    # 3rd position:
    1,-1,0 > 4
    1,-1,1 > 4
    1,-1,2 > 4
    # 2nd position:
    1,-2,0 > 3
    1,-2,1 > 3
    1,-2,2 > 3
    # 1st position:satisfies the rule listed above, skipping.
    

提交回复
热议问题