I am wondering what tf.strided_slice()
operator actually does.
The doc says,
To a first order, this operation extracts a slice of size end - begin from a tensor input starting at the location specified by begin. The slice continues by adding stride to the begin index until all dimensions are not less than end. Note that components of stride can be negative, which causes a reverse slice.
And in the sample,
# 'input' is [[[1, 1, 1], [2, 2, 2]],
# [[3, 3, 3], [4, 4, 4]],
# [[5, 5, 5], [6, 6, 6]]]
tf.slice(input, [1, 0, 0], [2, 1, 3], [1, 1, 1]) ==> [[[3, 3, 3]]]
tf.slice(input, [1, 0, 0], [2, 2, 3], [1, 1, 1]) ==> [[[3, 3, 3],
[4, 4, 4]]]
tf.slice(input, [1, 1, 0], [2, -1, 3], [1, -1, 1]) ==>[[[4, 4, 4],
[3, 3, 3]]]
So in my understanding of the doc, the first sample (tf.slice(input, begin=[1, 0, 0], end=[2, 1, 3], strides=[1, 1, 1])
),
- resulting size is
end - begin = [1, 1, 3]
. The sample result shows[[[3, 3, 3,]]]
, that shape is[1, 1, 3]
, it seems OK. - the first element of the result is at
begin = [1, 0, 0]
. The first element of the sample result is3
, which isinput[1,0,0]
, it seems OK. - the slice continues by adding stride to the begin index. So the second element of the result should be
input[begin + strides] = input[2, 1, 1] = 6
, but the sample shows the second element is3
.
What strided_slice()
does?
(Note: method names in the samples and the last example is incorrect.)
strides
directly tobegin
strides
is used for?tf.strided_slice(input, [1, -1, 0], [2, -3, 3], [1, -1, 1])