Postprocessing Functions¶
Module: polygraphy.comparator
- class BasePostprocessFunc[source]¶
Bases:
objectBase class for post-processing functors, which transform an
IterationResultbefore it is compared. Subclasses implement__call__(IterationResult) -> IterationResultand are used as thepostprocess_funcargument toComparator.postprocess.
- class TopKPostprocessFunc(k=None)[source]¶
Bases:
BasePostprocessFuncA 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_funcargument toComparator.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: