Spec-Zone.ru › TensorFlow C++ 2.9

tensorflow::ops::GatherNd

#include <array_ops.h>

Gather слайсы из params в Tensor с формой, заданной indices.

Краткое описание

indices — это K-мерный целочисленный тензор, лучше всего представляемый как (K-1)-мерный тензор индексов в params, где каждый элемент определяет срез params:

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

В то время как в tf.gatherindices определяются срезы в axis размерности params, в tf.gather_nd, indices определяет срезы в первых N измерениях params, где N = indices.shape[-1].

Последнее измерение indices может быть не больше ранга params:

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

Последнее измерение indices соответствует элементам (если indices.shape[-1] == params.rank) или срезам (если indices.shape[-1] < params.rank) вдоль размерности indices.shape[-1] params. Тензор вывода имеет форму

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.

Аргументы:

  • scope: Объект Scope
  • params: Тензор, из которого необходимо извлечь значения.
  • indices: Тензор индексов.

Возвращает:

  • Output: Значения из params собраны по индексам, заданным indices, с формой indices.shape[:-1] + params.shape[indices.shape[-1]:].
Конструкторы и деструкторы
GatherNd(const ::tensorflow::Scope & scope, ::tensorflow::Input params, ::tensorflow::Input indices)
Общедоступные атрибуты
operation
Operation
output
::tensorflow::Output
Общедоступные функции
node() const
::tensorflow::Node *
operator::tensorflow::Input() const
operator::tensorflow::Output() const

Общедоступные атрибуты

операция

Operation operation

выход

::tensorflow::Output output

Общедоступные функции

GatherNd

 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 

© 2022 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 4.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/versions/r2.9/api_docs/cc/class/tensorflow/ops/gather-nd

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API