# Lightweight Human Ear Recognition Based on Attention Mechanism and Feature Fusion
## 2 Related Works
### CBAM Attention Mechanism  
The attention mechanism assigns different weights to different parts of the image, so that the network pays attention to the important information of the target and ignores other secondary information. At present, the commonly used attention mechanisms mainly include SENet [18], CANet [19], ECANet [20] and CBAM [21].  
SENet channel attention strengthens the expression ability of the network by establishing the relationship between the channel features of the feature map, thereby improving the sensitivity of the channel and enabling the network to improve its information utilization. ECANet is based on SENet, abandoning the fully connected layer, but using 1\(\times\)1 convolution to capture the relationship between channels to avoid the impact of incomplete information caused by dimensionality reduction. CANet is a lightweight attention that obtains location information by changing the pooling method. It not only avoids the problem of information loss, but also considers direction-related location information. CBAM is a lightweight attention method combined with Channel Attention Module (CAM) and Spatial Attention Module (SAM), which uses CAM and SAM in turn for feature maps. CAM enables the network to learn channels containing key information, and SAM enables the network to learn key information on the channel feature map. The structure of CBAMNet is shown in Figure 1a.  
Firstly, the input feature map will go through the CAM module, as shown in Figure 1b. The feature map in the channel is compressed and the weights are assigned, so that the network can play an important role in analyzing the channel where the key information is located, as shown in Equations (1) and (2).  
\[Ft=M_{C}(F)\otimes F \tag{1}\] \[M_{c}(F) =\sigma(MLP(AvgPool(F))+MLP(MaxPool(F)))\] (2) \[=\sigma\Big{(}W_{1}\Big{(}W_{0}\Big{(}F^{c}_{avg}\Big{)}+W_{1}(W_ {0}(F^{c}_{\max}))\Big{)}\]  
where \(F\) is the input feature and \(F\in R^{H\times W\times C}\), \(M_{C}(F)\) is a one-dimensional channel attention feature map, \(\sigma\) is a Sigmoid activation function, \(MLP\) is a multi-layer perception, \(W_{1}\) and \(W_{0}\) are two shared weights, \(F^{c}_{avg}\) and \(F^{c}_{\max}\) represent the average pooling feature map and the maximum pooling feature map, respectively.  
Then, it will enter the SAM module, as shown in Figure 1c, and use the results of CAM output as CAM input, use the spatial relationship between features to generate a spatial attention map, keep the spatial dimension unchanged, compress the channel dimension and enable the network to learn the location information of key information.  
Figure 1: CBAMNet. (**a**) The structure of CBAMNet; (**b**) CAM; (**c**) SAM.  
The SAM module is shown in Equations (3) and (4).  
\[F^{\prime\prime}=M_{\mathrm{S}}(F\prime)\otimes F\prime \tag{3}\]  
\[M_{\mathrm{s}}(F,\prime) =\sigma\big{(}f^{\prime\times 7}([AvgPool(F^{\prime});MaxPool(F \prime)])\big{)} \tag{4}\] \[=\sigma\big{(}f^{\prime\times 7}\Big{(}\big{[}F^{\mathrm{s}}_{avg}; F^{\mathrm{s}}_{\mathrm{max}}\Big{]}\Big{)}\big{)}\]  
where \(M_{\mathrm{s}}(F,\prime)\) is a one-dimensional spatial attention feature map, \(F^{\mathrm{s}}_{avg}\) and \(F^{\mathrm{s}}_{\mathrm{max}}\) represent the average pooling feature map and the maximum pooling feature map, respectively.  
The four attention mechanisms introduced have their own advantages and disadvantages. Among them, the CBAM attention mechanism considers both spatial information and channel information, which can improve the feature extraction ability. Therefore, this paper uses CBAM to improve the ear recognition rate of the YOLOv5s-MG method and the YOLOv5s-MG-CBAM method is constructed.