代码语言:javascript复制
def strided_slice(input_,
begin,
end,
strides=None,
begin_mask=0,
end_mask=0,
ellipsis_mask=0,
new_axis_mask=0,
shrink_axis_mask=0,
var=None,
name=None):
"""Extracts a strided slice from a tensor.
'input'= [[[1, 1, 1], [2, 2, 2]], [[3, 3, 3], [4, 4, 4]], [[5, 5, 5], [6, 6, 6]]]
来把输入变个型,可以看成3维的tensor,从外向为1,2,3维
代码语言:javascript复制[
[
[1,1,1]
[2,2,2]
]
[
[3,3,3]
[4,4,4]
]
[
[5,5,5]
[6,6,6]
]
]
以tf.strided_slice(input, [0,0,0], [2,2,2], [1,2,1])调用为例,start = [0,0,0] , end = [2,2,2], stride = [1,2,1],求一个[start, end)的一个片段,注意end为开区间 第1维 start = 0 , end = 2, stride = 1, 所以取 0 , 1行,此时的输出
代码语言:javascript复制output1=
[
[
[1,1,1]
[2,2,2]
]
[
[3,3,3]
[4,4,4]
]
]
第2维时, start = 0 , end = 2 , stride = 2, 所以只能取0行,此时的输出
代码语言:javascript复制output2=
[
[
[1,1,1]
]
[
[3,3,3]
]
]
第3维的时候,start = 0, end = 2, stride = 1, 可以取0,1行,此时得到的就是最后的输出
代码语言:javascript复制output3=
[
[
[1,1]
]
[
[3,3]
]
]
整理之后最终的输出为: [[[1,1],[3,3]]] 类似代码如下:
代码语言:javascript复制import tensorflow as tf
data = [[[1, 1, 1], [2, 2, 2]],
[[3, 3, 3], [4, 4, 4]],
[[5, 5, 5], [6, 6, 6]]]
x = tf.strided_slice(data,[0,0,0],[1,1,1])
with tf.Session() as sess:
print(sess.run(x))