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]:]
Обратите внимание, что на процессоре, если обнаружен индекс за пределами границ, возвращается ошибка. На графическом процессоре, если обнаружен индекс за пределами границ, в соответствующее значение вывода записывается 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