Abstract
In the context of single-label classification, despite the huge success of deep learning, the commonly used cross-entropy loss function ignores the intricate inter-class relationships that often exist in real-life tasks such as age classification. In this work, we propose to leverage these relationships between classes by training deep nets with the exact squared Earth Mover's Distance (also known as Wasserstein distance) for single-label classification. The squared EMD loss uses the predicted probabilities of all classes and penalizes the miss-predictions according to a ground distance matrix that quantifies the dissimilarities between classes. We demonstrate that on datasets with strong inter-class relationships such as an ordering between classes, our exact squared EMD losses yield new state-of-the-art results. Furthermore, we propose a method to automatically learn this matrix using the CNN's own features during training. We show that our method can learn a ground distance matrix efficiently with no inter-class relationship priors and yield the same performance gain. Finally, we show that our method can be generalized to applications that lack strong inter-class relationships and still maintain state-of-the-art performance. Therefore, with limited computational overhead, one can always deploy the proposed loss function on any dataset over the conventional cross-entropy.
Introduction
Standard single-label classification models typically rely on Softmax Cross-Entropy (XE) loss. While effective, XE treats all incorrect predictions as equally wrong. For instance, in age estimation, misclassifying an "Adult" as a "Teenager" is penalized the same as misclassifying them as a "Baby." This ignores the inherent ordinal structure of the labels.
As shown in Figure 1, two different predicted distributions can yield the same XE loss despite one being qualitatively better. By incorporating inter-class relationships, we can guide the model to produce more sensible error distributions that reflect the underlying structure of the data.
Methodology
The proposed approach utilizes the Squared Earth Mover’s Distance (EMD²) to quantify the cost of misclassification based on a "ground distance" between classes.
EMD² for Ordered Classes
For ordinal datasets where classes follow a natural sequence (like age groups), EMD² has a simple, closed-form solution: it is the sum of squared differences between the Cumulative Distribution Functions (CDFs) of the prediction and the ground truth. This formulation is differentiable and well-suited for gradient-based optimization.
Self-Guided EMD
To handle cases where class relationships are not predefined, we introduce a "Self-Guided" mechanism. The model learns the ground distance matrix ($D$) dynamically during training:
- Feature Centroids: Each class is represented by the mean of its features from the penultimate layer of the CNN.
- Distance Matrix: The distance between classes is calculated as the Euclidean distance between these centroids.
- Hybrid Training: To ensure stability, the model is "jump-started" with standard XE before EMD² is introduced as a regularizer to refine class boundaries and capture inter-class relationships.
Experimental Results
The method was evaluated on several benchmarks, including Adience (age estimation), AADB (image aesthetics), and ImageNet (general object classification).
Performance on Age Estimation
On the Adience dataset, EMD²-based models achieved significant improvements over standard baselines. As detailed in the results table, the VGG-based model using EMD reached a state-of-the-art Exact Match (AEM) accuracy of 61.1%, outperforming standard XE (60.9%) and previous specialized architectures.
Convergence and Generalization
Beyond accuracy, EMD² models demonstrated faster convergence, often reaching target accuracy in approximately 1/3 the time required by XE. On ImageNet, where classes lack a linear order, the EMD² regularizer maintained performance without degradation, proving it is a safe and effective addition to general classification pipelines.
Conclusion
By penalizing "far-misses" more heavily than "near-misses," EMD² loss encourages models to learn a more structured and continuous feature space. This leads to improved accuracy on ordinal tasks and significantly faster convergence. The self-guided approach further extends this benefit to datasets without explicit class hierarchies, making it a versatile tool for modern deep learning applications.
Summary updated