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 | |
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
© 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/api_docs/cc/class/tensorflow/ops/gather-nd