# A Novel Object Detection Method of Pointer Meter Based on Improved YOLOv4-Tiny
## 2 Pmd-Yolo
### Attentional Mechanism
#### 2.3.1 Channel attention mechanism  
The structure of the channel attention mechanism is shown in Figure 6, and it can be seen from the figure that the input feature map is \(F\)(W \(\times\) H \(\times\) C). The basic process of the channel attention mechanism is as follows. First, global maximum pooling and global average pooling are performed on the height and width of the input feature map to generate two feature layers (\(F_{max}\), \(F_{avg}\)) with size 1 \(\times\) 1 \(\times\) C to map the channel information, and two 1 \(\times\) 1 convolution kernels are used to adjust the number of channels of \(F_{max}\) and \(F_{avg}\) to integrate the feature information; ReLU activation function is used once between the two 1 \(\times\) 1 convolutions, and the adjusted two feature layers are added element by element. Then, the channel attention feature map \(M_{c}\) is obtained through the operation of the sigmoid activation function; finally, \(F_{c}\) can be obtained by multiplying the feature map \(M_{c}\) and the input feature map \(F\) element by element. In experiments, the model performance is improved and the number of model parameters is reduced by using this channel attention mechanism instead of the SE mechanism in GhostNet. The calculation formula of the whole process is as follows.  
\[M_{c}=\sigma(f_{\rm C}^{1\times 1}(\Phi(f_{\rm C/8}^{1\times 1}(MaxPool(F)))+f_{ \rm C}^{1\times 1}(\Phi(f_{\rm C/8}^{1\times 1}AvgPool(F))))) \tag{1}\]  
\[F_{c}=M_{c}\otimes F \tag{2}\]  
where \(\sigma\) denotes sigmoid activation function, \(\Phi\) denotes ReLU activation function, MaxPool and AvgPool denote global max pooling and global average pooling, respectively, \(f_{\rm C/8}^{1\times 1}\) denotes convolution kernel with size 1 \(\times\) 1 and output channel C/8, \(f_{\rm C}^{1\times 1}\) denotes convolution kernel with size 1 \(\times\) 1 and output channel C, and \(\otimes\) denotes element-by-element multiplication.  
Figure 4: The structure of GhostNet.  
Figure 5: The structure of CBAM.  
The spatial attention mechanism is shown in Figure 7. The \(F_{c}(\text{W}\times\text{H}\times\text{C})\) generated by the previous channel attention mechanism is used as the input. The basic process of the spatial attention mechanism is as follows. First, global average pooling and global max pooling are performed in the channel dimensions to generate two feature maps with size \(\text{W}\times\text{H}\times 1\), and two feature maps are concatenated together in the channel dimensions to obtain a feature map with size \(\text{W}\times\text{H}\times 2\). Then, the number of channels of the feature map is adjusted by using a convolution kernel of size \(7\times 7\), and the spatial attention feature map \(M_{s}\) is obtained by the operation of the sigmoid activation function; finally, \(F_{s}\) can be obtained by multiplying the feature map \(M_{s}\) and the input feature map \(F_{c}\) element by element. The calculation formula of the whole process is as follows.  
\[M_{s}=\sigma(BN(f^{7\times 7}([AvgPool(F_{c});MaxPool(F_{c})]))) \tag{3}\]  
\[F_{s}=M_{s}\otimes F_{c} \tag{4}\]  
where \(\sigma\) denotes the sigmoid activation function, MaxPool and AvgPool denote global max pooling and global average pooling, respectively, \(f^{7\times 7}\) denotes convolution kernel with size \(7\times 7\), BN denotes batch normalization, and \(\otimes\) denotes element-by-element multiplication.