Abstract
We introduce UniLoss, a unified framework to generate surrogate losses for training deep networks with gradient descent, reducing the amount of manual design of task-specific surrogate losses. Our key observation is that in many cases, evaluating a model with a performance metric on a batch of examples can be refactored into four steps: from input to real-valued scores, from scores to comparisons of pairs of scores, from comparisons to binary variables, and from binary variables to the final performance metric. Using this refactoring we generate differentiable approximations for each non-differentiable step through interpolation. Using UniLoss, we can optimize for different tasks and metrics using one unified framework, achieving comparable performance compared with task-specific losses. We validate the effectiveness of UniLoss on three tasks and four datasets.
Introduction
In deep learning, a persistent "loss-metric mismatch" exists. While we aim for high accuracy or Average Precision (AP), these metrics are typically non-differentiable due to discrete operations, making them unsuitable for direct optimization via gradient descent. Consequently, researchers manually design surrogate losses—such as Cross-Entropy for accuracy or Mean Squared Error (MSE) on heatmaps for pose estimation. This manual design is often a "dark art," requiring extensive trial-and-error and hyperparameter tuning. UniLoss addresses this by providing a unified framework that automatically generates differentiable surrogate losses, allowing models to optimize directly for the target evaluation metric.
The UniLoss Framework
UniLoss makes any metric differentiable through a two-step strategy: refactoring and interpolation.
Refactoring the Metric Pipeline
Most performance metrics can be decomposed into a sequence of four stages:
- Scores: The network produces real-valued outputs.
- Comparisons: Scores are compared (e.g., via subtraction) to determine relative rankings or thresholds.
- Binaries: The results of comparisons are converted into binary variables (0 or 1) using a non-differentiable step function.
- Metric Aggregation: These binary variables are aggregated into the final performance score.
Differentiable Approximation via Interpolation
To enable gradient-based training, UniLoss replaces the non-differentiable components with "soft" approximations. The step function in the binary conversion stage is replaced by a Sigmoid function. For the final aggregation, UniLoss employs Multivariate Interpolation (specifically, Inverse Distance Weighting). Since the full space of binary configurations is too large, the framework samples "anchors"—representative binary states—to construct a smooth, differentiable surface that guides the gradient toward better performance.
Experimental Evaluation
The authors validated UniLoss across three distinct tasks: unbalanced binary classification (MNIST), multi-class classification (CIFAR-10/100), and human pose estimation (MPII).
Key Results
UniLoss achieves performance comparable to, and sometimes exceeding, hand-tuned task-specific losses:
- Pose Estimation (MPII): UniLoss achieved 95.77% PCKh, matching the best-performing hand-tuned MSE loss (95.74%) without needing to tune the Gaussian heatmap variance ($\sigma$).
- Image Classification (CIFAR-10): UniLoss reached 91.64% accuracy, slightly outperforming standard Cross-Entropy (91.49%).
- Ranking (MNIST AP): On the unbalanced task, UniLoss achieved an AP of 0.9988, effectively identical to the baseline.
Discussion and Conclusion
The core insight of UniLoss is the universality of comparisons: almost any discrete performance metric can be refactored into binary comparisons. By treating the metric as a landscape and smoothing it through interpolation, UniLoss reduces the human effort required for loss function design. Instead of mathematical derivation, the task becomes one of refactoring evaluation code.
While promising, UniLoss faces challenges in computational complexity for metrics with quadratic pairwise comparisons. Future work may involve more sophisticated anchor sampling and automatic code analysis to fully automate the transition from evaluation metric to differentiable loss function.
Summary updated