NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Fisher Discriminant Triplet and Contrastive Losses for Training Siamese Networks

Benyamin Ghojogh, Milad Sikaroudi, Sobhan Shafiei, Hamid R. Tizhoosh, Fakhri Karray, Mark Crowley · DOI

Introduction

Siamese networks are fundamental to metric learning, where models are trained to map similar items close together and dissimilar items far apart in a high-dimensional embedding space. Traditionally, this is achieved using Triplet Loss (comparing an anchor, a neighbor, and a distant sample) or Contrastive Loss (comparing pairs). However, these standard approaches focus on individual point-to-point Euclidean distances, often neglecting the broader statistical distribution of classes.

This paper introduces two novel loss functions, Fisher Discriminant Triplet (FDT) and Fisher Discriminant Contrastive (FDC). By integrating principles from classical Fisher Discriminant Analysis (FDA), these losses optimize the "scatter" of data points rather than just simple distances. This leads to superior feature extraction and enhanced generalization, particularly in complex domains like medical imaging.

Methodology

The proposed architecture utilizes a hybrid approach. A standard "backbone" network (e.g., ResNet) extracts features into a latent space. This is followed by a final linear projection layer, denoted as $U$, which maps the data into the final feature space.

Architecture of the proposed Siamese network with linear projection layer U.

The core innovation lies in the loss functions:

  1. Scatter Matrices: Instead of point-wise distances, the model calculates Intra-class scatter ($S_W$) (within-class variance) and Inter-class scatter ($S_B$) (between-class variance) within each mini-batch.
  2. Fisher Criterion: The objective is to minimize $S_W$ while maximizing $S_B$, effectively tightening class clusters while pushing them further apart.
  3. Regularization: To prevent weight explosion and ensure stability, a regularization parameter ($\lambda$) and a "total scatter" penalty are introduced, keeping the embedding space bounded.
  4. FDT vs. FDC: FDT applies these statistical principles to triplets, while FDC applies them to pairs.

Experimental Setup

The effectiveness of FDT and FDC was evaluated across several datasets:

  • MNIST: Used in a "small data" regime (500 triplets) to test learning efficiency.
  • CRC (Colorectal Cancer): A histopathology dataset with eight tissue types.
  • TCGA (The Cancer Genome Atlas): A large collection of cancer subtype images.
  • Generalization (TCGA-CRC): A cross-domain test where the model is trained on TCGA and tested on CRC to evaluate robustness to different image sources.

Results and Discussion

The Fisher-based losses demonstrated significant improvements in class separation and generalization. Using 1-Nearest Neighbor (1-NN) accuracy:

  • MNIST: FDT achieved 85.74% accuracy, outperforming standard triplet loss (82.21%).
  • Generalization (TCGA-CRC): FDC reached 98.10% accuracy, compared to 96.55% for standard contrastive loss.
UMAP visualizations comparing standard losses with FDT and FDC on medical imaging datasets.

UMAP visualizations confirm that FDT and FDC create tighter, more distinct clusters than traditional methods. A key insight is the "global" nature of these losses; by considering the statistical variance of the entire mini-batch, they capture class relationships more effectively than local point-to-point comparisons. Furthermore, the linear projection layer $U$ acts as a critical fine-tuner, organizing features in a highly discriminative manner.

Conclusion

The integration of Fisher Discriminant Analysis into Siamese networks provides a robust framework for metric learning. While the method shows high sensitivity to the regularization parameter $\lambda$ and depends on mini-batch size for stable statistical estimates, its ability to generalize across disparate medical datasets is a major advancement. Future work may explore non-linear or kernel-based versions of these Fisher losses to further enhance discriminative power.

Summary updated

BibTeX
@inproceedings{ghojogh2020fisher,
  author = {Benyamin Ghojogh and Milad Sikaroudi and Sobhan Shafiei and Hamid R. Tizhoosh and Fakhri Karray and Mark Crowley},
  title = {{Fisher Discriminant Triplet and Contrastive Losses for Training Siamese Networks}},
  booktitle = {IJCNN},
  year = {2020},
  doi = {10.1109/ijcnn48605.2020.9206833},
}
Figure