GatherND#

バージョン名: GatherND-5

カテゴリー: データ移動

簡単な説明: GatherND は、入力テンソルからスライスを収集して、インデックスで指定された形状のテンソルにします。

詳細な説明: GatherND は、indices によって data からスライスを収集し、indices で指定された形状のテンソルを形成します。

indices は、操作で data テンソルから要素またはスライスを収集するインデックスを持つタプルの K 次元整数テンソルまたは K-1 次元テンソルです。indices テンソル内の位置 i_0, ..., i_{K-2} は、長さが indices.shape[-1] に等しいインデックス indices[i_0, ..., i_{K-2}] を持つタプルに対応します。このインデックス付きタプルにより、操作は data テンソルからスライスまたは要素を収集し、それを次の式のように出力の位置 i_0, ..., i_{K-2} に挿入します:

output[i_0, …, i_{K-2},:,…,:] = data[indices[i_0, …, i_{K-2}],:,…,:]

Indices テンソルの最後の次元は、data テンソルのランク以下でなければなりません (つまり、indices.shape[-1] <= data.rank)。出力の形状は、indices.shape[:-1] + data.shape[indices.shape[-1]:] として計算できます。

例 1 は、GatherNDデータテンソルの要素をどのように操作するかを示しています:

indices = [[0, 0], 
           [1, 0]] 
data    = [[1, 2], 
           [3, 4]] 
output  = [1, 3]

例 2 は、GatherNDdata テンソルからのスライスをどのように操作するかを示しています:

indices = [[1], [0]] 
data    = [[1, 2], 
           [3, 4]] 
output  = [[3, 4], [1, 2]]

例 3 は、インデックステンソルに先行次元がある場合に GatherND がどのように動作するかを示しています:

indices = [[[1]], [[0]]] 
data    = [[1, 2], 
           [3, 4]] 
output  = [[[3, 4]], 
           [[1, 2]]]

属性:

  • batch_dims

    • 説明: batch_dims (b として示される) は、バッチを表す data テンソルと indices の先頭の次元数であり、GatherNDb+1 次元から収集を開始します。dataindices テンソルの最初の b 次元が等しい必要があります。batch_dims のデフォルト値以外の場合、出力形状は (multiplication of indices.shape[:b]) + indices.shape[b:-1] + data.shape[(indices.shape[-1] + b):] として計算されます。

      デフォルト以外の batch_dims 値が 1 より大きい場合、出力形状の計算は正しくありません。正しく計算するには、GatherND_8 操作を使用します。

    • 値の範囲: 整数であり、[0; min(data.rank, indices.rank)) に属します

    • タイプ: int

    • デフォルト値: 0

    • 必須: いいえ

例 4 は、GatherND がデフォルト以外の batch_dims 値の要素を収集する方法を示しています:

batch_dims = 1 
indices    = [[1], <--- this is applied to the first batch 
              [0]] <--- this is applied to the second batch, shape = (2, 1) 
data       = [[1, 2], <--- the first batch 
              [3, 4]] <--- the second batch, shape = (2, 2) 
output     = [2, 3], shape = (2)

例 5 は、GatherND がデフォルト以外の batch_dims 値のスライスを収集する方法を示しています:

batch_dims = 1 
indices = [[1], <--- this is applied to the first batch 
           [0]] <--- this is applied to the second batch, shape = (2, 1) 
data    = [[[1, 2, 3, 4], [ 5, 6, 7, 8], [ 9, 10, 11, 12]] <--- the first batch 
        [[13, 14, 15, 16], [17, 18, 19, 20], [21, 22, 23, 24]]] <--- the second batch, 
shape = (2, 3, 4) 
output  = [[ 5, 6, 7, 8], [13, 14, 15, 16]], shape = (2, 4)

複雑な例 6 は、GatherND がデフォルト以外の batch_dims 値の先行次元を使用してスライスを収集する方法を示しています:

batch_dims = 2 
indices = [[[[1]], <--- this is applied to the first batch 
            [[0]], 
            [[2]]], 
            [[[0]], 
            [[2]], 
            [[2]]] <--- this is applied to the sixth batch 
          ], shape = (2, 3, 1, 1) 
data = [[[1, 2, 3, 4], <--- this is the first batch 
            [ 5, 6, 7, 8], 
            [ 9, 10, 11, 12]] 
            [[13, 14, 15, 16], 
            [17, 18, 19, 20], 
            [21, 22, 23, 24]] <--- this is the sixth batch  
          ] <--- the second batch, shape = (2, 3, 4) 
output   = [[2], [5], [11], [13], [19], [23]], shape = (6, 1)

入力:

  • 1: T タイプの data テンソル。これは 1 以上のランクのテンソルです。必須。

  • 2: T_IND タイプの indices テンソル。これは 1 以上のランクのテンソルです。このテンソルのすべてのインデックスは [0, s-1] の範囲内にある必要があります。s は、このインデックスが適用される対応する次元です。必須

出力:

  • 1: T タイプの収集された値を持つテンソル。

タイプ

  • T: サポートされるタイプ。

  • T_IND: サポートされている整数タイプ。

<layer id="1" type="GatherND"> 
    <data batch_dims=0 /> 
    <input> 
        <port id="0"> 
            <dim>1000</dim> 
            <dim>256</dim> 
            <dim>10</dim> 
            <dim>15</dim> 
        </port> 
        <port id="1"> 
            <dim>25</dim> 
            <dim>125</dim> 
            <dim>3</dim> 
        </port> 
    </input> 
    <output> 
        <port id="3"> 
            <dim>25</dim> 
            <dim>125</dim> 
            <dim>15</dim> 
        </port> 
    </output> 
</layer>
<layer id="1" type="GatherND"> 
    <data batch_dims=2 /> 
    <input> 
        <port id="0"> 
            <dim>30</dim> 
            <dim>2</dim> 
            <dim>100</dim> 
            <dim>35</dim> 
        </port> 
        <port id="1"> 
            <dim>30</dim> 
            <dim>2</dim> 
            <dim>3</dim> 
            <dim>1</dim> 
        </port> 
    </input> 
    <output> 
        <port id="3"> 
            <dim>60</dim> 
            <dim>3</dim> 
            <dim>35</dim> 
        </port> 
    </output> 
</layer>