ICompositeLoss<T>
Interfaces · AiDotNet.Interfaces
A model whose training objective is a WEIGHTED SUM over several named outputs, declared rather than hand-assembled at each call site.
Known implementations: ABCNet<T>
How It Works
WHY DECLARED RATHER THAN COMPOSED BY THE CALLER, which is what PyTorch does. In PyTorch a multi-output
model returns a tuple and every training loop writes the combination by hand —
criterion(out.logits, y) + 0.4 * criterion(out.aux_logits, y) for Inception. That is explicit,
which is its virtue, but nothing can INSPECT it: no tool can report which term dominates, no test can
assert that a branch is supervised at all, and a loop that forgets a term produces a model that
silently never trains part of itself. That is precisely the failure this interface exists to make
impossible — ABCNet’s recognizer went untrained and no test noticed, because there was nothing to
notice with.
WHY NOT HIDDEN COLLECTION, which is what Keras does. add_loss lets any layer contribute a term
the framework silently sums, and the documented cost is that the objective becomes unreadable: you
cannot look at the training path and know what is being optimised. A declaration keeps the
explicitness of the PyTorch approach while adding the introspection PyTorch lacks — the terms are
named, weighted, enumerable, and therefore assertable.
The declaration also lets a test harness stop guessing. Given named outputs with shapes and losses, a harness can GENERATE a correct target per output instead of manufacturing one flat tensor and hoping it fits — which is what neither PyTorch nor Keras can do, because in neither does the model say what it needs.
Properties
| Property | Summary |
|---|---|
IReadOnlyList<OutputSpec<T>> DeclaredOutputs { get; } |
The objective’s terms, in a stable order. |
Methods
| Method | Summary |
|---|---|
IReadOnlyList<Tensor<T>> ComputeOutputs(Tensor<T> input) |
Runs the model and returns every declared output, in DeclaredOutputs order. |