Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
przepływ tensorowy:: ops:: TopK
#include <nn_ops.h>
Znajduje wartości i indeksy k
największych elementów ostatniego wymiaru.
Streszczenie
Jeśli danymi wejściowymi jest wektor (ranga-1), znajduje k
największych wpisów w wektorze i wyświetla ich wartości i indeksy jako wektory. Zatem values[j]
to j
-ty największy wpis w input
, a jego indeks to indices[j]
.
W przypadku macierzy (odpowiednio danych wejściowych o wyższej randze) oblicza k
górnych wpisów w każdym wierszu (odpowiednio wektor wzdłuż ostatniego wymiaru). Zatem,
values.shape = indices.shape = input.shape[:-1] + [k]
Jeśli dwa elementy są równe, element o niższym indeksie pojawia się jako pierwszy.
Argumenty:
- zakres: Obiekt Scope
- wejście: 1-D lub wyższe z ostatnim wymiarem co najmniej
k
. - k: 0-D. Liczba górnych elementów, których należy szukać wzdłuż ostatniego wymiaru (wzdłuż każdego wiersza w przypadku macierzy).
Opcjonalne atrybuty (patrz Attrs
):
- sorted: Jeśli true, wynikowe
k
elementów zostanie posortowanych według wartości w kolejności malejącej.
Zwroty:
- Wartości
Output
: k
największych elementów w każdym ostatnim przekroju wymiarowym. - Indeksy
Output
: Indeksy values
w obrębie ostatniego wymiaru input
.
Publiczne funkcje statyczne |
---|
Sorted (bool x) | |
Atrybuty publiczne
Funkcje publiczne
Publiczne funkcje statyczne
Posortowane
Attrs Sorted(
bool x
)
O ile nie stwierdzono inaczej, treść tej strony jest objęta licencją Creative Commons – uznanie autorstwa 4.0, a fragmenty kodu są dostępne na licencji Apache 2.0. Szczegółowe informacje na ten temat zawierają zasady dotyczące witryny Google Developers. Java jest zastrzeżonym znakiem towarowym firmy Oracle i jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-07-27 UTC.
[null,null,["Ostatnia aktualizacja: 2025-07-27 UTC."],[],[],null,["# tensorflow::ops::TopK Class Reference\n\ntensorflow::ops::TopK\n=====================\n\n`#include \u003cnn_ops.h\u003e`\n\nFinds values and indices of the `k` largest elements for the last dimension.\n\nSummary\n-------\n\nIf the input is a vector (rank-1), finds the `k` largest entries in the vector and outputs their values and indices as vectors. Thus `values[j]` is the `j`-th largest entry in `input`, and its index is `indices[j]`.\n\nFor matrices (resp. higher rank input), computes the top `k` entries in each row (resp. vector along the last dimension). Thus, \n\n```cplint\nvalues.shape = indices.shape = input.shape[:-1] + [k]\n```\n\n\u003cbr /\u003e\n\nIf two elements are equal, the lower-index element appears first.\n\nArguments:\n\n- scope: A [Scope](/versions/r2.3/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope) object\n- input: 1-D or higher with last dimension at least `k`.\n- k: 0-D. Number of top elements to look for along the last dimension (along each row for matrices).\n\n\u003cbr /\u003e\n\nOptional attributes (see [Attrs](/versions/r2.3/api_docs/cc/struct/tensorflow/ops/top-k/attrs#structtensorflow_1_1ops_1_1_top_k_1_1_attrs)):\n\n- sorted: If true the resulting `k` elements will be sorted by the values in descending order.\n\n\u003cbr /\u003e\n\nReturns:\n\n- [Output](/versions/r2.3/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output) values: The `k` largest elements along each last dimensional slice.\n- [Output](/versions/r2.3/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output) indices: The indices of `values` within the last dimension of `input`.\n\n\u003cbr /\u003e\n\n| ### Constructors and Destructors ||\n|---|---|\n| [TopK](#classtensorflow_1_1ops_1_1_top_k_1a0c8404c5e20cae7d52b460b213d13bf4)`(const ::`[tensorflow::Scope](/versions/r2.3/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, ::`[tensorflow::Input](/versions/r2.3/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` input, ::`[tensorflow::Input](/versions/r2.3/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` k)` ||\n| [TopK](#classtensorflow_1_1ops_1_1_top_k_1ad55e14f1c8e36a07ae7e3e5189ce1de6)`(const ::`[tensorflow::Scope](/versions/r2.3/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, ::`[tensorflow::Input](/versions/r2.3/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` input, ::`[tensorflow::Input](/versions/r2.3/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` k, const `[TopK::Attrs](/versions/r2.3/api_docs/cc/struct/tensorflow/ops/top-k/attrs#structtensorflow_1_1ops_1_1_top_k_1_1_attrs)` & attrs)` ||\n\n| ### Public attributes ||\n|-----------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|\n| [indices](#classtensorflow_1_1ops_1_1_top_k_1a702b5fcc223806a5b43892c840294e6e) | `::`[tensorflow::Output](/versions/r2.3/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output) |\n| [operation](#classtensorflow_1_1ops_1_1_top_k_1a6772614af084e9178999f8b10e356ce4) | [Operation](/versions/r2.3/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation) |\n| [values](#classtensorflow_1_1ops_1_1_top_k_1a3d754e075cd5e04093e27e60a6a07727) | `::`[tensorflow::Output](/versions/r2.3/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output) |\n\n| ### Public static functions ||\n|------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------|\n| [Sorted](#classtensorflow_1_1ops_1_1_top_k_1ac5e55d49539ee3457dc1a432480e85c2)`(bool x)` | [Attrs](/versions/r2.3/api_docs/cc/struct/tensorflow/ops/top-k/attrs#structtensorflow_1_1ops_1_1_top_k_1_1_attrs) |\n\n| ### Structs ||\n|----------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|\n| [tensorflow::ops::TopK::Attrs](/versions/r2.3/api_docs/cc/struct/tensorflow/ops/top-k/attrs) | Optional attribute setters for [TopK](/versions/r2.3/api_docs/cc/class/tensorflow/ops/top-k#classtensorflow_1_1ops_1_1_top_k). |\n\nPublic attributes\n-----------------\n\n### indices\n\n```text\n::tensorflow::Output indices\n``` \n\n### operation\n\n```text\nOperation operation\n``` \n\n### values\n\n```text\n::tensorflow::Output values\n``` \n\nPublic functions\n----------------\n\n### TopK\n\n```gdscript\n TopK(\n const ::tensorflow::Scope & scope,\n ::tensorflow::Input input,\n ::tensorflow::Input k\n)\n``` \n\n### TopK\n\n```gdscript\n TopK(\n const ::tensorflow::Scope & scope,\n ::tensorflow::Input input,\n ::tensorflow::Input k,\n const TopK::Attrs & attrs\n)\n``` \n\nPublic static functions\n-----------------------\n\n### Sorted\n\n```text\nAttrs Sorted(\n bool x\n)\n```"]]