TopK
tensorflow C++ API
Finds values and indices of thek
largest elements for the last dimension.
Summary
If the input is a vector (rank-1), finds thek
largest entries in the vector and outputs their values and indices as vectors. Thusvalues[j]
is thej
-th largest entry ininput
, and its index isindices[j]
.
For matrices (resp. higher rank input), computes the topk
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 (seeAttrs
):
- sorted: If true the resulting
k
elements will be sorted by the values in descending order.
Returns:
Output
values: Thek
largest elements along each last dimensional slice.Output
indices: The indices ofvalues
within the last dimension ofinput
.
TopK block
Source link : https://github.com/EXPNUNI/enuSpaceTensorflow/blob/master/enuSpaceTensorflow/tf_nn.cpp
Argument:
- Scope scope : A Scope object (A scope is generated automatically each page. A scope is not connected.)
- Input input: connect Input node.
- Input k: connect Input node.
- TopK::Attrs atttrs: input attrs in values. ex)sorted:true;
Return:
- Output indices: Output object of TopK class object.
- Output values: Output object of TopK class object.
Result:
- std::vector(Tensor) result_indices: Returned object of executed result by calling session.
- std::vector(Tensor) result_values: Returned object of executed result by calling session.