The implementation of PairLoss in When Deep Learning Meets Metric Learning: Remote Sensing Image Scene Classification via Learning Discriminative CNNs.
You can follow these tutorial Caffe and link to compile your own caffe.
As is define in our paper, our PairLoss function:
where $y_{i,j}=\begin{cases} +1 & y_{i} = y_{j} \-1 & y_{i} \not = y_{j} \\end{cases}$.
Therefore, our loss function needs four inputs which are divided into 2 groups.
One group calculates the loss of the inter-class, another calculates that of the intra-class.
If you utilize our loss function on your task, you can adopt a 4-stream siamese structure or slice operation.
@article{cheng2018deep,
title={When Deep Learning Meets Metric Learning: Remote Sensing Image Scene Classification via Learning Discriminative CNNs},
author={Cheng, Gong and Yang, Ceyuan and Yao, Xiwen and Guo, Lei and Han, Junwei},
journal={IEEE Transactions on Geoscience and Remote Sensing},
year={2018},
publisher={IEEE}
}