Stay organized with collections
Save and categorize content based on your preferences.
tensorflow::ops::TopK
#include <nn_ops.h>
Finds values and indices of the k
largest elements for the last dimension.
Summary
If 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]
.
For matrices (resp. higher rank input), computes the top k
entries in each row (resp. vector along the last dimension). Thus,
values.shape = indices.shape = input.shape[:-1] + [k]
If two elements are equal, the lower-index element appears first.
Arguments:
- scope: A Scope object
- input: 1-D or higher with last dimension at least
k
.
- k: 0-D. Number of top elements to look for along the last dimension (along each row for matrices).
Optional attributes (see Attrs
):
- sorted: If true the resulting
k
elements will be sorted by the values in descending order.
Returns:
Output
values: The k
largest elements along each last dimensional slice.
Output
indices: The indices of values
within the last dimension of input
.
Public static functions
|
Sorted(bool x)
|
|
Public attributes
Public functions
Public static functions
Sorted
Attrs Sorted(
bool x
)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-04-20 UTC.
[null,null,["Last updated 2020-04-20 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/r1.15/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/r1.15/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/r1.15/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output) values: The `k` largest elements along each last dimensional slice.\n- [Output](/versions/r1.15/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/r1.15/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, ::`[tensorflow::Input](/versions/r1.15/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` input, ::`[tensorflow::Input](/versions/r1.15/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/r1.15/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, ::`[tensorflow::Input](/versions/r1.15/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` input, ::`[tensorflow::Input](/versions/r1.15/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` k, const `[TopK::Attrs](/versions/r1.15/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/r1.15/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output) |\n| [operation](#classtensorflow_1_1ops_1_1_top_k_1a6772614af084e9178999f8b10e356ce4) | [Operation](/versions/r1.15/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation) |\n| [values](#classtensorflow_1_1ops_1_1_top_k_1a3d754e075cd5e04093e27e60a6a07727) | `::`[tensorflow::Output](/versions/r1.15/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/r1.15/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/r1.15/api_docs/cc/struct/tensorflow/ops/top-k/attrs) | Optional attribute setters for [TopK](/versions/r1.15/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```"]]