テンソルフロー::作戦::ギャザーND

#include <array_ops.h>

paramsからのスライスを、 indicesで指定された形状を持つTensor集めます

まとめ

indicesは K 次元の整数テンソルであり、 paramsへのインデックスの (K-1) 次元テンソルとして考えるのが最も適切です。ここで、各要素はparamsのスライスを定義します:

output[\\(i_0, ..., i_{K-2}\\)] = params[indices[\\(i_0, ..., i_{K-2}\\)]]

tf.gather indicesではparamsの最初の次元にスライスを定義しますが、 tf.gather_ndでは、 indices paramsの最初のN次元にスライスを定義します ( N = indices.shape[-1]

indicesの最後の次元は、最大でもparamsのランクになります:

indices.shape[-1] <= params.rank

indicesの最後の次元は、要素 ( indices.shape[-1] == params.rankの場合) またはparamsの次元indices.shape[-1]に沿ったスライス ( indices.shape[-1] < params.rankの場合) に対応します。 。出力テンソルの形状は

indices.shape[:-1] + params.shape[indices.shape[-1]:]
です。

CPU では、範囲外のインデックスが見つかった場合、エラーが返されることに注意してください。 GPU では、範囲外のインデックスが見つかった場合、対応する出力値に 0 が格納されます。

以下にいくつかの例を示します。

行列への単純なインデックス付け:

    indices = [[0, 0], [1, 1]]
    params = [['a', 'b'], ['c', 'd']]
    output = ['a', 'd']

インデックス付けを行列にスライスします。

    indices = [[1], [0]]
    params = [['a', 'b'], ['c', 'd']]
    output = [['c', 'd'], ['a', 'b']]

3 テンソルへのインデックス付け:

    indices = [[1]]
    params = [[['a0', 'b0'], ['c0', 'd0']],
              [['a1', 'b1'], ['c1', 'd1']]]
    output = [[['a1', 'b1'], ['c1', 'd1']]]

    indices = [[0, 1], [1, 0]]
    params = [[['a0', 'b0'], ['c0', 'd0']],
              [['a1', 'b1'], ['c1', 'd1']]]
    output = [['c0', 'd0'], ['a1', 'b1']]

    indices = [[0, 0, 1], [1, 0, 1]]
    params = [[['a0', 'b0'], ['c0', 'd0']],
              [['a1', 'b1'], ['c1', 'd1']]]
    output = ['b0', 'b1']

マトリックスへのバッチインデックス作成:

    indices = [[[0, 0]], [[0, 1]]]
    params = [['a', 'b'], ['c', 'd']]
    output = [['a'], ['b']]

行列へのスライスのインデックス付けをバッチ化する:

    indices = [[[1]], [[0]]]
    params = [['a', 'b'], ['c', 'd']]
    output = [[['c', 'd']], [['a', 'b']]]

3 テンソルへのバッチインデックス作成:

    indices = [[[1]], [[0]]]
    params = [[['a0', 'b0'], ['c0', 'd0']],
              [['a1', 'b1'], ['c1', 'd1']]]
    output = [[[['a1', 'b1'], ['c1', 'd1']]],
              [[['a0', 'b0'], ['c0', 'd0']]]]

    indices = [[[0, 1], [1, 0]], [[0, 0], [1, 1]]]
    params = [[['a0', 'b0'], ['c0', 'd0']],
              [['a1', 'b1'], ['c1', 'd1']]]
    output = [[['c0', 'd0'], ['a1', 'b1']],
              [['a0', 'b0'], ['c1', 'd1']]]

    indices = [[[0, 0, 1], [1, 0, 1]], [[0, 1, 1], [1, 1, 0]]]
    params = [[['a0', 'b0'], ['c0', 'd0']],
              [['a1', 'b1'], ['c1', 'd1']]]
    output = [['b0', 'b1'], ['d0', 'c1']]

tf.gatherおよびtf.batch_gatherも参照してください。

引数:

  • スコープ:スコープオブジェクト
  • params: 値を収集するテンソル。
  • インデックス: インデックス テンソル。

戻り値:

  • Output : indicesで指定されたインデックスから収集されたparamsの値 (形状indices.shape[:-1] + params.shape[indices.shape[-1]:]

コンストラクターとデストラクター

GatherNd (const :: tensorflow::Scope & scope, :: tensorflow::Input params, :: tensorflow::Input indices)

パブリック属性

operation
output

公共機能

node () const
::tensorflow::Node *
operator::tensorflow::Input () const
operator::tensorflow::Output () const

パブリック属性

手術

Operation operation

出力

::tensorflow::Output output

公共機能

ギャザーND

 GatherNd(
  const ::tensorflow::Scope & scope,
  ::tensorflow::Input params,
  ::tensorflow::Input indices
)

ノード

::tensorflow::Node * node() const 

演算子::tensorflow::入力

 operator::tensorflow::Input() const 

演算子::tensorflow::出力

 operator::tensorflow::Output() const