# SupCon-MPL-DP: Supervised Contrastive Learning with Meta Pseudo Labels for Deepfake Image Detection
## 3 Proposed SupCon-MPL-Based Deepfake Detection
### SupCon-MPL Loss Function
 \tag{7}\]  
The MPL loss \(g_{T}^{(t)}\) calculates the difference between the hard pseudo label \(y_{u}\), which is the maximum value extracted from the pseudo labels generated by \(T\) through \(x_{u}\), and the logit. Here, \(emb_{u}^{T}\) denotes the embedding value derived by passing the labeled data \(x_{u}\) through \(ENC_{T}\):\[g_{T}^{(t)}=h\cdot\
abla_{\theta_{T}}CE\Big{(}\hat{y}_{u},CLF_{T}\Big{(}emb_{u}^{T };\theta_{T}\Big{)}\Big{)}|_{\theta_{T}=\theta_{T}^{(t)}} \tag{8}\]  
The feedback factor \(h\) of \(S\) was calculated in the same way as the original Meta Pseudo Labels [37], using Taylor expansion to calculate the difference before and after the training of \(S\). In the proposed method, we approximated \(h\) using the difference from the CE loss value for the labeled data after \(S\) was trained to the value before training. This allows the final loss value to converge as the training progresses. \[h=CE\Big{(}y_{I},S\Big{(}x_{I};\theta_{S}^{(t+1)}\Big{)}\Big{)}-CE\Big{(}y_{I},S\Big{(}x_{I};\theta_{S}^{(t)}\Big{)}\Big{)} \tag{9}\]  
The final loss function of \(ClF_{T}\) is composed of the sum of each loss function value:  
\[\theta_{T}^{(t+1)}=\theta_{T}^{(t)}-\eta s\cdot\Big{(}g_{T}^{(t)}+g_{T,supervised }^{(t)}\Big{)} \tag{10}\]  
\(S\) is trained through unlabeled data. The loss function of the student model's encoder \(ENC_{S}\), denoted as \(g_{S,contrast}^{(t)}\), is trained utilizing SupConLoss [38], akin to \(ENC_{T}\). It leverages \((x_{u},\hat{y}_{u})\), comprising an unlabeled image \(x_{u}\) paired with pseudo labels \(\hat{y}_{u}\), generated by \(T\):  
\[g_{S,contrast}^{(t)} \tag{11}\] \[=\
abla_{\theta_{T}}SupConLoss(RandAugment_{a}(x_{u}),RandAugment _{b}(x_{u}),\hat{y}_{u})|_{\theta_{S}=\theta_{S}^{(t)}}\]  
\(ENC_{S}\) is also promptly updated following the computation of the \(g_{S,contrast}^{(t)}\):  
\[\theta_{S,ENC}^{(t+1)}=\theta_{S,ENC}^{(t)}-\eta_{S}\cdot g_{S,contrast}^{(t)} \tag{12}\]  
The loss function of \(CLF_{S}\) is calculated using CE loss for the hard pseudo label \(\hat{y}_{u}\) of \(T\) for \(x_{u}\) and the prediction of \(S\). Here, \(emb_{u}^{S}\) denotes the embedding value derived by passing the labeled data \(x_{u}\) through \(ENC_{S}\):  
\[\theta_{S}^{(t+1)}=\theta_{S}^{(t)}-\eta s\cdot\
abla_{\theta_{S}}CE\Big{(} \hat{y}_{u},CLF_{S}\Big{(}emb_{u}^{S};\theta_{S}\Big{)}\Big{)}|_{\theta_{S}= \theta_{S}^{(t)}} \tag{13}\]  
The SupConLoss in \(g_{T,contrast}^{(t)}\), \(g_{S,contrast}^{(t)}\) on the teacher model \(T\) and student model \(S\) are as follows:  
\[SupConLoss=\sum_{i\in I}SupConLoss_{i}=\sum_{i\in I}\frac{-1}{|P(i)|}\sum_{p \in P(i)}log\frac{exp\big{(}z_{i}\cdot z_{p}/\tau\big{)}}{\sum_{a\in A(i)} exp(z_{i}\cdot z_{a}/\tau)} \tag{14}\]  
Here, \(i\in I\equiv\{1,\cdots,2N\}\) is the index of the randomly augmented data, and \(P(i)\equiv\big{\{}p\in A(i):y_{p}=y_{i}\big{\}}\) is the set of indices for all positives in the batch (since \(y_{p}\) and \(y_{i}\) are labels of images that have been randomly augmented from \(y_{I}\), they are the same as \(y_{I}\)). \(z_{i}\) and \(z_{p}\) are the embedding values of each randomly augmented image in \((RandAugment_{a}(x_{I}),RandAugment_{b}(x_{I}))\) passed through the encoder \(ENC\), and \(A(i)\equiv I\backslash\{i\}\), and \(\tau\) is the temperature parameter. In other words, the inner product between positive pairs (\(i\) and \(p\) are the same class but different samples) is maximized through \(exp\big{(}z_{i}\cdot z_{p}/\tau\big{)}\), and the inner product between negative pairs is minimized through \(exp(z_{i}\cdot z_{a}/\tau)\), so that the SupConLoss is minimized. The training process of the proposed SupCon-MPL model for deepfake detection is shown in Algorithm 1.