Inter-Class Angular Loss for Convolutional Neural Networks

Le Hui, Xiang Li, Chen Gong, Meng Fang, Joey Tianyi Zhou, Jian Yang

Abstract

Standard softmax loss often fails to distinguish between visually similar "hard pairs," such as cats and dogs, because it does not explicitly manage the relationships between different classes. We introduce Inter-Class Angular Loss (ICAL), a plug-and-play loss function that forces networks to enlarge the angles between class vectors in feature space. This approach significantly boosts discriminative power across both vision and text classification tasks by explicitly maximizing inter-class separability.

Introduction: The Softmax Blind Spot

In a typical Convolutional Neural Network (CNN), the final layer uses a softmax function to assign probabilities to classes. While effective, softmax treats all classes as equally distinct, ignoring the reality that some classes are harder to separate than others. For example, in the CIFAR-10 dataset, a model is far more likely to confuse a "cat" with a "dog" than a "dog" with a "ship."

This confusion is directly tied to the geometry of the feature space. If the learned vectors representing two classes are separated by a small angle, the model struggles to tell them apart. Existing solutions like Triplet Loss or Center Loss focus on intra-class compactness but often ignore inter-class relationships or suffer from high computational costs.

Methodology: Inter-Class Angular Loss (ICAL)

ICAL introduces a regularization term to the standard softmax loss that explicitly minimizes cosine similarity (and thus maximizes the angle) between different class vectors.

Key Innovations

  • Angular Modeling: ICAL uses the cosine distance between class vectors ($W_i$ and $W_j$) to measure similarity. By minimizing this similarity, the model "pushes" the class vectors away from each other on the unit hypersphere.
  • Computational Efficiency: Calculating similarity between every possible pair of classes normally takes $O(K^2)$ time. ICAL leverages a mathematical trick—normalizing the weight matrix and using vector sums—to reduce this complexity to $O(K)$, making it scalable for large datasets.
  • Continuous Hyperparameter: Unlike methods like Large-Margin Softmax (L-Softmax), which require discrete integer parameters, ICAL uses a continuous parameter ($\lambda$). This makes the model less sensitive to exact settings and easier to optimize.
Figure 2: Comparison of accuracy vs. tuning parameters between L-Softmax and ICAL. ICAL shows higher peak performance and greater stability across a range of values.

Experimental Evaluation

The researchers evaluated ICAL across diverse benchmarks:

  • Vision: Fashion-MNIST, CIFAR-10, and CIFAR-100 using architectures like ResNet, ResNeXt, Wide Residual Networks (WRN), and DenseNet.
  • Text: Five popular text classification datasets (MR, CR, Subj, MPQA, TREC) using both CNNs and LSTMs.

Key Results

  • Vision Performance: On CIFAR-100, adding ICAL to a ResNet-110 improved accuracy from 68.82% to 70.48%. On CIFAR-10+, WRN-28-10 reached 97.14% accuracy.
  • Text Performance: ICAL consistently outperformed baseline models. On the MPQA dataset, a standard CNN-sen-rand model improved from 83.4% to 85.2% accuracy.
  • Comparison to L-Softmax: On CIFAR-10, ICAL achieved 93.06% accuracy, outperforming the best L-Softmax configuration (92.42%).

Analysis and Discussion

The Angle-Accuracy Correlation

A clear trend emerges during training: as the minimum angle between class vectors increases, the model's accuracy improves. This confirms that inter-class separability is a primary driver of performance. Visualization of class scores shows that ICAL specifically helps in cases where a standard ResNet would misclassify an image by widening the angular margin.

Figure 1: Visualization of the correlation between confusion matrices, angular matrices, and feature space separation. As accuracy increases, the angular separation between classes becomes more pronounced.

Universality

ICAL provided consistent gains for LSTMs in text classification, suggesting that inter-class confusion is a fundamental property of the softmax function across different domains, not just limited to image processing.

Conclusion

ICAL offers a simple yet powerful way to improve the discriminative capability of neural networks. By focusing on the angular relationships between classes, it addresses the inherent limitations of standard softmax loss. Future work may explore its integration into more complex architectures and its application to tasks like metric learning or zero-shot learning.

Summary updated

BibTeX
@inproceedings{hui2019inter,
  author = {Le Hui and Xiang Li and Chen Gong and Meng Fang and Joey Tianyi Zhou and Jian Yang},
  title = {{Inter-Class Angular Loss for Convolutional Neural Networks}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2019},
  doi = {10.1609/aaai.v33i01.33013894},
}
Figure