Postprocessing Functions

Module: polygraphy.comparator

class PostprocessFunc[source]

Bases: object

Provides functions that can apply post-processing to IterationResult s.

static top_k(k=None)[source]

Creates a function that applies a Top-K operation to a IterationResult. Top-K will return the indices of the k largest values in the array.

Parameters:

k (Union[int, Tuple[int, int], Dict[str, int], Dict[str, Tuple[int, int]]]) –

The number of indices to keep and optionally the axis on which to operate. For example, a value of (5, 0) would keep the top 5 indices along axis 0.

If this exceeds the axis length, it will be clamped. This can be specified on a per-output basis by providing a dictionary. In that case, use an empty string (“”) as the key to specify default top-k value for outputs not explicitly listed. If no default is present, unspecified outputs will not be modified. Defaults to 10.

Returns:

The top-k function.

Return type:

Callable(IterationResult) -> IterationResult