## 4 Self-Attention Network for Portrait FER
### Loss Functions  
Loss function in our applications: Loss functions are critical components in machine learning as objective measures of how well an algorithm models a given dataset. They guide the model training process by adjusting the model parameters to minimize the loss and improve predictive accuracy. The choice of a loss function depends on various factors,including the nature of the problem, the data distribution, and the desired characteristics of the model. Different loss functions emphasize different aspects of model performance and may be more suitable for specific applications. Different loss functions are listed in Table 8.  
Loss Functions in FER Tasks: In the context of Facial Expression Recognition (FER) tasks, cross-entropy loss functions are primarily used to maximize the likelihood of correct classifications while minimizing incorrect classifications, especially with one-hot-encoded labels. While cross-entropy loss can significantly enhance model accuracy, it also risks diminishing the utility of information obtained from the model's outputs. In FER, each emotional label carries specific information, but the traditional cross-entropy approach might limit its applicability in emotion-related research. Proposed Novel Loss Function: We propose a novel loss function that integrates cross-entropy and Euclidean distance metrics to address these limitations. This combined approach aims to retain detailed information about emotional labels while guiding the model toward accurate predictions. Consequently, we proposed a novel loss function that integrates the cross-entropy and Euclidean distance metrics. \[Loss_{ce}=CE(f(X),targets) \tag{1}\]  
\[Loss_{dis}=MSE(Dis(3D(f(X)),centers),targets) \tag{2}\]  
\[Loss_{dis}=MSE(3D(f(X)),DVAlabels) \tag{3}\]  
Our proposed method employs three different loss functions to enhance the model's performance. Initially, we apply the cross-entropy loss to measure the discrepancy between the predicted categorical labels and the actual labels, which is a conventional approach in classification tasks (Equation (1)). Subsequently, we introduce a distance loss function that calculates the Euclidean distance between the predicted 3D labels and the pre-trained 3D emotion centers. This calculation involves an input image \(X\), from which the function \(f(X)\) derives an embedding vector. The \(3D()\) module is then responsible for generating the predicted 3D emotion labels, while \(Dis()\) computes the distance to the pre-trained 3D emotion centers obtained from PE3D (Equation (2)). This stage also includes an additional linear neural layer to produce a refined emotion logit vector based on the 3D emotion labels, applying a center-based mean square error loss to compute \(L_{dis}\) (Equation (2)). The third loss function is employed when the training dataset contains 3D labels, such as PE3D, optimizing the output 3D labels via mean square loss. Finally, the composite loss function (Equation (4)) incorporates different ratio parameters, optimized based on experimental results cited from the literature [87], with a balanced 1:1:1 ratio of the loss functions to achieve optimal results. If the 3D labels are available in the training set, the \(L_{dva}\) and \(Loss_{dis}\) will be added.