Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
dòng chảy căng:: ôi:: TopK
#include <nn_ops.h>
Tìm giá trị và chỉ số của k
phần tử lớn nhất cho chiều cuối cùng.
Bản tóm tắt
Nếu đầu vào là một vectơ (cấp 1), hãy tìm k
mục lớn nhất trong vectơ và xuất ra các giá trị cũng như chỉ số của chúng dưới dạng vectơ. Do đó, values[j]
là mục lớn nhất thứ j
trong input
và chỉ mục của nó indices[j]
.
Đối với ma trận (tương ứng với đầu vào có thứ hạng cao hơn), hãy tính k
mục hàng đầu trong mỗi hàng (vectơ tương ứng dọc theo chiều cuối cùng). Như vậy,
values.shape = indices.shape = input.shape[:-1] + [k]
Nếu hai phần tử bằng nhau thì phần tử có chỉ số thấp hơn sẽ xuất hiện đầu tiên.
Lập luận:
- phạm vi: Một đối tượng Phạm vi
- đầu vào: 1-D hoặc cao hơn với chiều cuối cùng ít nhất là
k
. - k: 0-D. Số phần tử trên cùng cần tìm dọc theo chiều cuối cùng (dọc theo mỗi hàng đối với ma trận).
Thuộc tính tùy chọn (xem Attrs
):
- được sắp xếp: Nếu đúng thì
k
phần tử kết quả sẽ được sắp xếp theo các giá trị theo thứ tự giảm dần.
Trả về:
- Giá trị
Output
: k
phần tử lớn nhất dọc theo mỗi lát chiều cuối cùng. - Chỉ số
Output
: Chỉ số của values
trong chiều cuối cùng của input
.
Các hàm tĩnh công khai |
---|
Sorted (bool x) | |
Thuộc tính công khai
Chức năng công cộng
Các hàm tĩnh công khai
Đã sắp xếp
Attrs Sorted(
bool x
)
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-07-27 UTC.
[null,null,["Cập nhật lần gần đây nhất: 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```"]]