Link Search Menu Expand Document

TopK


tensorflow C++ API

tensorflow::ops::TopK

Finds values and indices of theklargest elements for the last dimension.


Summary

If the input is a vector (rank-1), finds theklargest 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 topkentries 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 leastk.
  • 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 resultingkelements will be sorted by the values in descending order.

Returns:

  • Outputvalues: Theklargest elements along each last dimensional slice.
  • Outputindices: The indices ofvalueswithin 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.

Using Method