Gather

バージョン名: Gather-8

カテゴリー: データ移動

簡単な説明: Gather 操作は、2 番目の入力テンソルと 3 番目の入力の軸で指定されたインデックスに従って、最初の入力テンソルのデータのスライスを取得します。この操作のセマンティクスは TensorFlow Gather 操作と同じですが、負のインデックスのサポートも含まれています。

詳細な説明:

output[p_0, p_1, ..., p_{axis-1}, i_b, ..., i_{M-1}, p_{axis+1}, ..., p_{N-1}] =
   data[p_0, p_1, ..., p_{axis-1}, indices[p_0, p_1, ..., p_{b-1}, i_b, ..., i_{M-1}], p_{axis+1}, ..., p_{N-1}]

dataindices および axis がそれぞれ 1 番目、2 番目、3 番目の入力からのテンソルである場合、b はバッチ次元の数です。N および M はそれぞれ dataindices テンソルの次元数です。インデックスに許可される値は [-data.shape[axis], data.shape[axis] - 1] の範囲内です。インデックス値が許容範囲を超える場合、対応するインデックスの出力データはゼロで埋められます (例 7)。

属性:

  • batch_dims

    • 説明: batch_dims (b とも表記) は、バッチを表す data テンソルと indices の先頭の次元数であり、Gatherb 次元から収集を開始します。dataindices テンソルの最初の b 次元が等しい必要があります。batch_dims がゼロより小さい場合、正規化された batch_dims = indices.rank + batch_dims 値が使用されます。

    • 値の範囲: [-min(data.rank, indices.rank); min(data.rank, indices.rank)]batch_dims' <= axis'。ここで、batch_dims'axis' は、正規化された batch_dimsaxis の値を表します。

    • タイプ: T_AXIS

    • デフォルト値: 0

    • 必須: いいえ

例 1 - デフォルトの batch_dims 値を使用:

batch_dims = 0
axis = 0

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

例 2 - デフォルト以外の batch_dims 値を使用:

batch_dims = 1
axis = 1

indices = [[0, 0, 4], <-- this is applied to the first batch
           [4, 0, 0]]  <-- this is applied to the second batch
indices_shape = (2, 3)

data    = [[1, 2, 3, 4, 5],  <-- the first batch
           [6, 7, 8, 9, 10]]  <-- the second batch
data_shape = (2, 5)

output  = [[ 1, 1, 5],
           [10, 6, 6]]
output_shape = (2, 3)

例 3 - デフォルト以外の batch_dims 値を使用:

batch_dims = 2
axis = 2

indices = [[[0, 0, 4],  <-- this is applied to the first batch, index = (0, 0)
            [4, 0, 0]],  <-- this is applied to the second batch, index = (0, 1)

           [[1, 2, 4],  <-- this is applied to the third batch, index = (1, 0)
            [4, 3, 2]]]  <-- this is applied to the fourth batch, index = (1, 1)
indices_shape = (2, 2, 3)

data    = [[[1, 2, 3, 4, 5],  <-- the first batch, index = (0, 0)
            [6, 7, 8, 9, 10]],  <-- the second batch, index = (0, 1)

           [[11, 12, 13, 14, 15],  <-- the third batch, index = (1, 0)
            [16, 17, 18, 19, 20]]]  <-- the fourth batch, index = (1, 1)
data_shape = (2, 2, 5)

output  = [[[ 1, 1, 5],
            [10, 6, 6]],

           [[12, 13, 15],
            [20, 19, 18]]]
output_shape = (2, 2, 3)

例 4 - axis > batch_dims を使用:

batch_dims = 1
axis = 2

indices = [[1, 2, 4],  <-- this is applied to the first batch
           [4, 3, 2]]  <-- this is applied to the second batch
indices_shape = (2, 3)

data = [[[[ 1,  2,  3,  4], <-- first batch
          [ 5,  6,  7,  8],
          [ 9, 10, 11, 12],
          [13, 14, 15, 16],
          [17, 18, 19, 20]]],

        [[[21, 22, 23, 24], <-- second batch
          [25, 26, 27, 28],
          [29, 30, 31, 32],
          [33, 34, 35, 36],
          [37, 38, 39, 40]]]]
data_shape = (2, 1, 5, 4)

output = [[[[ 5,  6,  7,  8],
            [ 9, 10, 11, 12],
            [17, 18, 19, 20]]],

          [[[37, 38, 39, 40],
            [33, 34, 35, 36],
            [29, 30, 31, 32]]]]
output_shape = (2, 1, 3, 4)

例 5 - 負の batch_dims 値を使用:

batch_dims = -1  <-- normalized value will be indices.rank + batch_dims = 2 - 1 = 1
axis = 1

indices = [[0, 0, 4], <-- this is applied to the first batch
           [4, 0, 0]]  <-- this is applied to the second batch
indices_shape = (2, 3)

data    = [[1, 2, 3, 4, 5],  <-- the first batch
           [6, 7, 8, 9, 10]]  <-- the second batch
data_shape = (2, 5)

output  = [[ 1, 1, 5],
           [10, 6, 6]]
output_shape = (2, 3)

例 6 - 負のインデックスを使用:

batch_dims = 0
axis = 0

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

例 7 - インデックスが範囲外:

batch_dims = 0
axis = 0

indices = [3, 10, -20]
data    = [1, 2, 3, 4, 5]
output  = [4, 0, 0]

入力:

  • 1: 任意のデータを持つ T タイプの data テンソル。必須。

  • 2: 収集するインデックスを持つ T_IND タイプの indices テンソル。インデックスの 0D テンソル (スカラー) も許可されます。インデックス値の範囲は [-data.shape[axis], data.shape[axis] - 1] です。インデックスの負の値は、data.shape[axis] からの逆インデックスを示します。必須。

  • 3: T_AXIS タイプのスカラーまたは 1D テンソル axis は、データを収集する次元インデックスです。例えば、axis が 1 に等しい場合は、最初の次元で収集が実行されることを意味します。負の axis は逆インデックスを意味し、値 axis = data.rank + axis に正規化されます。許可される値は、[-len(data.shape), len(data.shape) - 1] および axis' >= batch_dims' です。ここで、axis'batch_dims' は、正規化された batch_dimsaxis の値を表します。必須。

出力:

  • 1: indices によって収集された data テンソルの要素で構成される T タイプの結果のテンソル。出力テンソルの形状は次のとおりです。

data.shape[:axis] + indices.shape[batch_dims:] + data.shape[axis + 1:]

タイプ:

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

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

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

例:

<layer ... type="Gather" version="opset8">
    <data batch_dims="1" />
    <input>
        <port id="0">
            <dim>2</dim>
            <dim>64</dim>
            <dim>128</dim>
        </port>
        <port id="1">
            <dim>2</dim>
            <dim>32</dim>
            <dim>21</dim>
        </port>
        <port id="2"/>   <!--  axis = 1  -->
    </input>
    <output>
        <port id="2">
            <dim>2</dim>
            <dim>32</dim>
            <dim>21</dim>
            <dim>128</dim>
        </port>
    </output>
</layer>