Class TopK
Represents a TopK
layer. This calculates the top-K largest or smallest elements of an input tensor along a given axis.
This layer calculates both the values tensor of the top-K elements and the indices tensor of the top-K elements as outputs.
Inherited Members
Namespace: Unity.Sentis.Layers
Syntax
[Serializable]
public class TopK : Layer
Constructors
TopK(String, String, String, Int32, Boolean, Boolean, String[])
Initializes and returns an instance of TopK
layer.
Declaration
public TopK(string name, string input, string k, int axis, bool largest, bool sorted, string[] outputNames)
Parameters
Type | Name | Description |
---|---|---|
String | name | The name to use for the values tensor of the layer. |
String | input | The name to use for the input tensor of the layer. |
String | k | The name to use for the single value 1D tensor containing the number of elements to calculate. |
Int32 | axis | The axis along which to perform the top-K operation. |
Boolean | largest | Whether to calculate the top-K largest elements. If this is |
Boolean | sorted | Whether to return the elements in sorted order in the output tensor. |
String[] | outputNames | A two-element array containing the names to use for the values and indices output tensors of the layer respectively. |
Fields
axis
The axis along which to perform the top-K operation.
Declaration
public int axis
Field Value
Type | Description |
---|---|
Int32 |
largest
Whether to calculate the top-K largest elements. If this is false
the layer calculates the top-K smallest elements.
Declaration
public bool largest
Field Value
Type | Description |
---|---|
Boolean |
sorted
Whether to return the elements in sorted order in the output tensor.
Declaration
public bool sorted
Field Value
Type | Description |
---|---|
Boolean |
Methods
Execute(Tensor[], ExecutionContext)
Executes the layer using the operations and variables from the ExecutionContext
and returns the output tensor.
If the layer has more than one output, output tensors are saved to variables.
Declaration
public override Tensor Execute(Tensor[] inputTensors, ExecutionContext ctx)
Parameters
Type | Name | Description |
---|---|---|
Tensor[] | inputTensors | |
ExecutionContext | ctx |
Returns
Type | Description |
---|---|
Tensor |