提取張量的跨步切片(廣義 Python 數組索引)。
用法
tf.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
)參數
-
input_一個Tensor。 -
begin一個int32或int64Tensor。 -
end一個int32或int64Tensor。 -
strides一個int32或int64Tensor。 -
begin_maskint32掩碼。 -
end_maskint32掩碼。 -
ellipsis_maskint32掩碼。 -
new_axis_maskint32掩碼。 -
shrink_axis_maskint32掩碼。 -
varinput_或 None 對應的變量 -
name操作的名稱(可選)。
返回
-
Tensor與input類型相同。
另見tf.slice。
大多數用戶不想直接調用此操作,而是希望使用 NumPy-style 切片語法(例如 tensor[..., 3:4:-1, tf.newaxis, 3] ),該語法通過 tf.Tensor.getitem 和 tf.Variable.getitem 得到支持。此操作的接口是切片語法的低級編碼。
粗略地說,這個操作從給定的 input_ 張量中提取了一個大小為 (end-begin)/stride 的切片。從 begin 指定的位置開始,切片通過將 stride 添加到索引繼續,直到所有維度不小於 end 。請注意,步幅可以是負數,這會導致反向切片。
給定一個 Python 切片 input[spec0, spec1, ..., specn] ,該函數將按如下方式調用。
begin , end 和 strides 將是長度為 n 的向量。 n 通常不等於input_ 張量的秩。
在每個掩碼字段 (begin_mask , end_mask , ellipsis_mask , new_axis_mask , shrink_axis_mask) 中,第 i 個位將對應於第 i 個規範。
如果設置了begin_mask 的第i 位,則忽略begin[i],並使用該維度中可能的最大範圍。 end_mask 的工作方式類似,除了結束範圍。
7x8x9 張量上的 foo[5:,:,:3] 等價於 foo[5:7,0:8,0:3] 。 foo[::-1] 反轉形狀為 8 的張量。
如果設置ellipsis_mask的第i位,則將根據需要在其他維度之間插入盡可能多的未指定維度。 ellipsis_mask 中隻允許有一個非零位。
例如,形狀 10x3x3x10 張量上的 foo[3:5,...,4:5] 等價於 foo[3:5,:,:,4:5] 並且 foo[3:5,...] 等價於 foo[3:5,:,:,:] 。
如果 new_axis_mask 的第 i 位被設置,則 begin , end 和 stride 將被忽略,並在輸出張量的此時添加一個新的長度為 1 維。
例如,foo[:4, tf.newaxis,:2] 將產生形狀 (4, 1, 2) 張量。
如果設置 shrink_axis_mask 的第 i 位,則意味著第 i 個規範將維度縮小 1,取索引 begin[i] 處的值。在這種情況下,end[i] 和 strides[i] 將被忽略。例如,在 Python 中,可能會執行 foo[:, 3,:],這將導致 shrink_axis_mask 等於 2。
注意:begin 和end 是zero-indexed。 strides 條目必須非零。
t = tf.constant([[[1, 1, 1], [2, 2, 2]],
[[3, 3, 3], [4, 4, 4]],
[[5, 5, 5], [6, 6, 6]]])
tf.strided_slice(t, [1, 0, 0], [2, 1, 3], [1, 1, 1]) # [[[3, 3, 3]]]
tf.strided_slice(t, [1, 0, 0], [2, 2, 3], [1, 1, 1]) # [[[3, 3, 3],
# [4, 4, 4]]]
tf.strided_slice(t, [1, -1, 0], [2, -3, 3], [1, -1, 1]) # [[[4, 4, 4],
# [3, 3, 3]]]
相關用法
- Python tf.strings.substr用法及代碼示例
- Python tf.strings.reduce_join用法及代碼示例
- Python tf.strings.regex_full_match用法及代碼示例
- Python tf.strings.regex_replace用法及代碼示例
- Python tf.strings.length用法及代碼示例
- Python tf.strings.bytes_split用法及代碼示例
- Python tf.strings.as_string用法及代碼示例
- Python tf.strings.unsorted_segment_join用法及代碼示例
- Python tf.strings.lower用法及代碼示例
- Python tf.strings.split用法及代碼示例
- Python tf.strings.upper用法及代碼示例
- Python tf.strings.unicode_decode_with_offsets用法及代碼示例
- Python tf.strings.join用法及代碼示例
- Python tf.strings.to_hash_bucket用法及代碼示例
- Python tf.strings.ngrams用法及代碼示例
- Python tf.strings.to_hash_bucket_strong用法及代碼示例
- Python tf.strings.unicode_decode用法及代碼示例
- Python tf.strings.unicode_encode用法及代碼示例
- Python tf.strings.format用法及代碼示例
- Python tf.strings.to_hash_bucket_fast用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.strided_slice。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
