Learning Anytime Predictions in Neural Networks via Adaptive Loss Balancing

Hanzhang Hu, Debadeepta Dey, Martial Hebert, J. Andrew Bagnell · DOI

Abstract

This work considers the trade-off between accuracy and test-time computational cost of deep neural networks (DNNs) via anytime predictions from auxiliary predictions. Specifically, we optimize auxiliary losses jointly in an adaptive weighted sum, where the weights are inversely proportional to the average of each loss. Intuitively, this balances the losses to have the same scale. We demonstrate theoretical considerations that motivate this approach from multiple viewpoints, including connecting it to optimizing the geometric mean of the expectation of each loss, an objective that ignores the scale of losses. Experimentally, the adaptive weights induce more competitive anytime predictions on multiple recognition datasets and models than non-adaptive approaches, including weighing all losses equally. In particular, anytime neural networks (ANNs) can achieve the same accuracy faster using adaptive weights on a small network than using static constant weights on a large one. For problems with high performance saturation, we also show a sequence of exponentially deepening ANNs can achieve near-optimal anytime results at any budget, at the cost of a constant fraction of extra computation.

Introduction: The "All-or-Nothing" Problem

Deep Neural Networks (DNNs) have achieved remarkable accuracy across various tasks, but they typically operate in an "all-or-nothing" fashion: the entire network must be executed before a prediction is available. In time-sensitive applications like autonomous driving, robotics, or web filtering, computational budgets can vary dynamically. A "good enough" answer delivered immediately is often more valuable than a perfect answer that arrives too late.

Architecture of an Anytime Neural Network (ANN) with auxiliary prediction heads at intermediate layers.

Anytime Neural Networks (ANNs) address this by incorporating auxiliary prediction heads at intermediate layers. This allows the model to output a preliminary result early and refine it as more computation is performed. However, training these networks is challenging. Standard approaches that sum auxiliary losses often suffer from scale imbalances: early layers with high error rates can dominate the gradient, hindering the optimization of deeper, more accurate layers. Finding the right balance usually requires tedious manual tuning of static weights.

Methods: Adaptive Loss Balancing (AdaLoss)

The core contribution of this paper is AdaLoss, a simple adaptive weighting scheme for training ANNs. Instead of manually tuning static weights, AdaLoss sets the weight for each auxiliary loss to be inversely proportional to its running average. This effectively "normalizes" all losses to the same scale.

This approach ensures that a relative improvement in a shallow layer is treated as equally important as a relative improvement in a deep layer. The authors provide several theoretical justifications for this:

  • Likelihood Maximization: It can be viewed as maximizing the likelihood of a model with Gaussian noise where the variance is learned.
  • Geometric Mean Optimization: It is equivalent to optimizing the geometric mean of the expected losses, an objective that is naturally scale-invariant.

Exponentially Deepening Anytime Neural Networks (EANN)

For scenarios where accuracy eventually saturates, the authors propose EANNs. This method uses an ensemble of ANNs with exponentially increasing depths. By running these in sequence, the system ensures that at any given time budget, the prediction comes from a network that is near-optimal for that specific budget, incurring only a constant fraction of additional computational overhead.

Experimental Evaluation

The researchers evaluated AdaLoss on standard benchmarks including CIFAR-10, CIFAR-100, SVHN, and ImageNet. They applied the method to various architectures such as ResNets, DenseNets, and the Multi-Scale Dense Network (MSDNet).

Key Results: Efficiency and Performance

The experiments revealed that AdaLoss consistently provides superior accuracy-computation trade-offs compared to constant or linearly increasing weights.

Test Top-1 Error Rate vs. Computational Budget (FLOPS). A small ANN trained with AdaLoss outperforms a larger network trained with standard weights.

A particularly striking finding is that a small network trained with AdaLoss can achieve the same accuracy levels faster than a network twice its size trained with standard constant weights. Even on MSDNet—an architecture specifically designed for anytime prediction—switching to AdaLoss significantly improved performance, allowing a smaller MSDNet32 to match the accuracy of a larger MSDNet38.

Discussion and Future Work

AdaLoss provides a principled, parameter-free way to navigate the Pareto front of anytime prediction. While highly effective for auxiliary losses of the same type (e.g., cross-entropy), future research could explore its application in multi-task learning environments where losses have different units. Additionally, exploring gradient-norm normalization ("first-order" variants) could help handle loss functions with unknown offsets.

By balancing the importance of early and late predictions, AdaLoss enables the deployment of deep learning models that are both highly accurate and robust to varying computational constraints.

Summary updated

BibTeX
@misc{hu2017learning,
  author = {Hanzhang Hu and Debadeepta Dey and Martial Hebert and J. Andrew Bagnell},
  title = {{Learning Anytime Predictions in Neural Networks via Adaptive Loss Balancing}},
  year = {2017},
  eprint = {1708.06832},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1708.06832},
}
Figure