# Pupil Refinement Recognition Method Based on Deep Residual Network and Attention Mechanism
## 2 Pupil Refinement Recognition Methods
### External Attention Module  
The channel attention module mainly focuses on the importance of different channels in the feature map and adjusts the channel weights to enhance useful features and suppress useless features. However, this approach may ignore the spatial information inside the feature map, i.e., the importance of features at different locations for pupil recognition tasks is somewhat different. For this reason, by constructing an external attention module in which an external memory unit M is introduced, M is the learnable parameters, implicitly learns the features of the whole key and useful pupil features continuation training set, taking into account the potential connection between different samples, and this connection is meaningful for dealing with pupil feature samples, carving out the most essential features of all the pupil feature samples, and then extracting the more abstract and differentiated pupil features and improving the pupil refinement recognition effect [24]. The structure of the external attention module is shown in Figure 3.  
In the realization process, the key and useful pupil features extracted in Section 2.3 are taken as the features to be processed, and the key and useful infrared spectrum pupil features, for example, can be expressed as \(\chi^{\prime}\). The input key and useful pupil feature \(\chi^{\prime}\) are first transformed into a new feature space, similar to the self-attention mechanism, and \(\overset{\sim}{X}\) is obtained by its own linear transformation Linear Q (Conv 1 \(\times\) 1). The aim is to enhance the expressive power of pupil features and extract more abstract and discriminative pupil features and then to compute the attention matrix A of the external memory units M\({}_{\text{k}}\) to \(\overset{\sim}{X}^{\prime}\), with the following expression:  
\[\text{A}=\text{Norm}\left(\text{Linear}_{\text{Q}}(\chi^{\prime})\text{M}_{ \text{k}}^{\text{T}}\right)=\text{Norm}\left(\hat{\theta}_{\text{i}\text{j}^{ \prime}}\right) \tag{9}\]  
where \(\hat{\theta}_{\text{i}\text{j}^{\prime}}\) represents the similarity between the i\(\prime\)-th pixel in \(\overset{\sim}{X}^{\prime}\) and the j\({}^{\prime}\)-th column memory value in M\({}_{\text{k}}^{\text{T}}\). The application of dual-normalized Norm can avoid the attention failure problem caused by the excessive feature vector of a pupil. Double-normalized Norm  
Figure 3: External attention module.  
normalizes the rows and columns of the attention \(\hat{\theta}_{y,j^{\prime}}\) calculated by matrix multiplication. The realization process can be expressed as follows:  
\[\hat{\theta}_{y,j^{\prime}}=\frac{\mathrm{e}^{\hat{\theta}_{y,j^{\prime}}}}{ \sum\limits_{\mathrm{k}}\mathrm{e}^{\hat{\theta}_{k,j^{\prime}}}} \tag{10}\]  
The similarity feature matrix A is used to update the second external memory cell M\({}_{\mathrm{k}}\), instead of the first external memory unit M\({}_{\mathrm{k}}\). In this way, the capacity of the network can be increased, and then combined with the original pupil features, the final pupil features in the infrared spectrum processed by the external attention module can be obtained, and the expression is as follows:  
\[\mathrm{O}^{\prime}=\chi^{\prime}+\mathrm{AM}_{\mathrm{v}} \tag{11}\]  
Similarly, the final NIR spectral-domain pupil features O\({}^{\prime\prime}\) processed by the external attention module is obtained.