AutoLoss-Zero: Searching Loss Functions from Scratch for Generic Tasks

Hao Li, Tianwen Fu, Jifeng Dai, Hongsheng Li, Gao Huang, Xizhou Zhu

TL;DR

AutoLoss-Zero is a general framework that automatically discovers high-performing loss functions from scratch using only basic mathematical primitives. By employing an evolutionary algorithm paired with clever efficiency protocols, it finds novel, differentiable surrogate losses that outperform handcrafted ones across diverse tasks like semantic segmentation, object detection, and pose estimation.

What Problem Does This Paper Address?

Training a deep neural network requires a loss function, but there is often a fundamental "misalignment" between the loss we optimize (like Cross-Entropy) and the metric we actually care about (like Intersection-over-Union or Average Precision). Many of these target metrics are non-differentiable, meaning we can't calculate gradients for them directly.

Traditionally, researchers have bridged this gap by handcrafting complex surrogate losses. However, this requires significant human expertise and is usually task-specific—a loss designed for face recognition might not work for pose estimation. While some automated "AutoML" methods for loss search exist, they typically combine existing loss functions or use task-specific heuristics. AutoLoss-Zero aims to remove the human from the loop entirely, searching for the best loss function for any generic task starting from basic mathematical building blocks.

Methods

The authors treat a loss function as a computational graph (a rooted tree) where leaf nodes are inputs (predictions $\hat{y}$ and ground truths $y$) and internal nodes are primitive mathematical operators.

1. The Search Space

The search space is composed of:

  • Element-wise Operators: Basic math like Add, Mul, Log, Exp, Tanh, and Sqrt.
  • Aggregation Operators: Operations that exchange information across spatial or channel dimensions, such as Mean and Max-Pooling.

You can see the full set of primitives in the table below: Primitive operator set used in the search space

Primitive operator set used in the search space

The framework uses a variant of the evolutionary algorithm to navigate this space:

  • Initialization: Randomly generates computational graphs to a fixed depth.
  • Mutation: Evolves the population through Insertion, Deletion, and Replacement of nodes in the graph.
  • Tournament Selection: Picks the best-performing "parents" to produce the next generation of loss functions.

3. Efficiency Protocols

Searching from scratch is computationally expensive. To make it feasible, the authors introduced two key strategies:

  • Loss-Rejection Protocol: Before training a full network, a candidate loss is tested on a tiny set of samples. The framework checks if minimizing the candidate loss actually correlates with improving the target evaluation metric. If not, the loss is rejected immediately.
  • Gradient-Equivalence-Check: It identifies mathematically different formulas that produce identical gradients, preventing the system from wasting time re-evaluating redundant functions.

The overall pipeline is summarized in Figure 1: Overview of the AutoLoss-Zero search pipeline

Figure 1. Overview of the search pipeline.

Datasets

The authors validated AutoLoss-Zero across several major computer vision benchmarks:

  • PASCAL VOC 2012: Used for semantic segmentation tasks.
  • COCO: Used for object detection, instance segmentation, and pose estimation.
  • Cityscapes: Used to test how well the discovered losses generalize to new datasets.

Key Insights and Ideas

  • Starting from "Zero": By not relying on existing loss functions as a starting point, the model can discover non-intuitive mathematical structures that humans might never consider.
  • The Power of Rejection: The "Loss-Rejection Protocol" is the unsung hero of the paper. It allows the system to explore over a million candidate losses in just 48 hours by filtering out "junk" functions in milliseconds.
  • Generalization is Built-in: Losses discovered on a specific dataset (like COCO) and a specific backbone (like ResNet-50) were shown to perform excellently when transferred to different architectures and datasets, suggesting they capture the fundamental nature of the task.

Key Results

  • Superior Performance: In semantic segmentation, AutoLoss-Zero outperformed standard Cross-Entropy and several handcrafted alternatives across multiple metrics (mIoU, Boundary F1, etc.).
  • Competitive in Detection: For object detection on COCO, the searched losses were on par with or better than state-of-the-art handcrafted losses like GIoU.
  • Massive Speedup: The combination of the rejection protocol and equivalence checking resulted in a 5000x speedup in search efficiency compared to a naive evolutionary approach.
  • Metric-Specific Discovery: The search successfully found different optimal losses for different metrics. For example, the loss found for "Boundary F1" in segmentation looks very different from the one found for "mIoU."

The impact of these efficiency components is clearly visible in the ablation study: Ablation study showing how each component improves search efficiency

Figure 4. Ablation study on search efficiency of AutoLoss-Zero. Each curve presents the averaged evaluation scores over the top-5 loss functions in the current population.

Limitations and Future Work

  • Computational Cost: Despite the 5000x speedup, the search still requires significant resources (the authors used 4x NVIDIA V100 GPUs).
  • Search Space Depth: The current search is limited to a relatively shallow graph depth ($D=3$). Increasing this depth could lead to even more powerful losses but would exponentially increase the search space.
  • Manual Simplification: The final discovered formulas (like those in Table 8 of the paper) often contain redundant operations that the authors simplified manually. Automating this symbolic simplification would be a natural next step.
  • Domain Expansion: While "generic" for computer vision, it remains to be seen how well this framework translates to other domains like Natural Language Processing or Reinforcement Learning.

Summary updated

BibTeX
@misc{li2021autoloss,
  author = {Hao Li and Tianwen Fu and Jifeng Dai and Hongsheng Li and Gao Huang and Xizhou Zhu},
  title = {{AutoLoss-Zero: Searching Loss Functions from Scratch for Generic Tasks}},
  year = {2021},
  eprint = {2103.14026},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2103.14026},
}
Figure