ensemble
Prediction reducers for ensemble / TTA / voting workflows.
Pure callables on a sequence of per-point prediction tensors. They aggregate without knowing how the predictions were produced (live inference, saved files, multi-model fold ensemble, multi-seed voting). Each reducer ships as a function (call inline) and a class (instantiate when chosen by config).
Classes:
-
Ensemble–Base class for the class form of a prediction reducer.
-
MeanEnsemble–Class form of
mean_ensemble. -
VoteEnsemble–Class form of
vote_ensemble.
Functions:
-
mean_ensemble–Per-point mean across a list of prediction tensors.
-
vote_ensemble–Per-point majority-vote counts across a list of prediction tensors.
Ensemble
¶
Base class for the class form of a prediction reducer.
Subclasses implement forward to aggregate a sequence of per-point prediction tensors into one.
MeanEnsemble
¶
Bases: Ensemble
Class form of mean_ensemble.
Stateless wrapper for use when the reducer is chosen by config or stored as part of a pipeline.
Example
VoteEnsemble
¶
Bases: Ensemble
Class form of vote_ensemble.
Parameters:
-
num_classes(int) –Channel count for the one-hot encoding. Stored on the instance so
forwardmatches theCallable[[Sequence[Tensor]], Tensor]signature ofMeanEnsemble.
Example
mean_ensemble
¶
Per-point mean across a list of prediction tensors.
Parameters:
-
outputs(Sequence[Tensor]) –Sequence of \((N, C)\) tensors (typically softmax probabilities or logits). All must have the same shape.
Returns:
-
Tensor–Mean along the stacking dim, shape \((N, C)\).
vote_ensemble
¶
Per-point majority-vote counts across a list of prediction tensors.
Each output is argmax'd along its last dim, one-hot encoded with
num_classes channels, and summed across the ensemble. Take argmax of
the result to get the majority-vote labels per point; the raw counts are
useful for tie inspection.
Parameters:
-
outputs(Sequence[Tensor]) –Sequence of \((N, C)\) tensors. The argmax of each is taken, so either logits or probabilities work.
-
num_classes(int) –Channel count \(C\) used for the one-hot encoding. Must be at least
max(argmax(output)) + 1; pass the model'snum_classes.
Returns:
-
Tensor–Per-point class-vote counts, shape \((N, \text{num\_classes})\), dtype
-
Tensor–matching the inputs.