tensorflow::ops::GatherNd
#include <array_ops.h>
Gather слайсы из params в Tensor с формой, указанной в indices.
Summary
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 | |
output | |
| Общедоступные функции | |
|---|---|
node() const | ::tensorflow::Node * |
operator::tensorflow::Input() const | |
operator::tensorflow::Output() const | |
Общедоступные атрибуты
operation
Operation operation
output
::tensorflow::Output output
Общедоступные функции
GatherNd
GatherNd( const ::tensorflow::Scope & scope, ::tensorflow::Input params, ::tensorflow::Input indices )
node
::tensorflow::Node * node() const
operator::tensorflow::Input
operator::tensorflow::Input() const
operator::tensorflow::Output
operator::tensorflow::Output() const
© 2020 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/ops/gather-nd