Skip to main content
. 2025 Mar 12;25(6):1770. doi: 10.3390/s25061770
Algorithm 1: Training the similarity measurement model.
Input: Xtrain, selection operation S(·) , training epoch T, target model f
Output: the parameters of model D
1: for t = 0 to T-1 do
2:       feed x∈Xtrain into the target model f and obtain the label y=f(x)
3:       select a counterpart image for x , x′=Sy,  where  x′∈Xtrain
4:       generate an adversarial example xadv by attacking x
5:       feed xadv into f and obtain yadv=f(xadv)
6:       select a counterpart image for xadv , xadv′=Syadv , where xadv′∈Xtrain
7:       feed x, xadv, x′, xadv′ into the Encoder E:
           Fx=Ex,Fxadv=Exadv,Fx′=Ex′,Fx′adv=Ex′adv
8:       construct feature pairs:
           Fsim=concatFx,Fx′, labeled as 0;
          Fdif=concat(Fxadv,Fxadv′), labeled as 1
9:       feed Fsim and Fdif to model D
10:      optimize model D using cross-entropy loss
11: end for