Postprocessing Functions

Module: polygraphy.comparator

class BasePostprocessFunc[source]

Bases: object

Base class for post-processing functors, which transform an IterationResult before it is compared. Subclasses implement __call__(IterationResult) -> IterationResult and are used as the postprocess_func argument to Comparator.postprocess.

__call__(iter_result)[source]

Call self as a function.

class TopKPostprocessFunc(k=None)[source]

Bases: BasePostprocessFunc

A post-processing functor that replaces each output with the indices of its K largest values (a Top-K operation), optionally along a specified axis. Used as the postprocess_func argument to Comparator.postprocess.

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.

__call__(iter_result)[source]
Parameters:

iter_result (IterationResult) – The iteration result to post-process.

Returns:

The same IterationResult, modified in place.

Return type:

IterationResult

class PostprocessFunc[source]

Bases: object

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

static top_k(k=None)[source]

Deprecated: Use TopKPostprocessFunc instead.

Creates a TopKPostprocessFunc. See TopKPostprocessFunc for a description of the arguments.