# Faster RCNN Target Detection Algorithm Integrating CBAM and FPN
## 3 Model Design and Implementation
### Incorporate the CBAM Attention Mechanism  
The attention mechanism can selectively ignore some inefficient information in the image, focus on the efficient information, reduce the resource consumption of the inefficient part, improve the network utilization, and enhance the ability of object detection. Therefore, the CBAM attention mechanism is integrated into the feature extraction network, and the channel attention mechanism and spatial attention mechanism are connected [31] to form a simple but effective attention module, whose structure is shown in Figure 6.  
\begin{table}
\begin{tabular}{c c c} \hline
**Network Layer** & **Output** & **52 Layer** \\ \hline Convolution layer 1 & \(112\times 112\) & \(7\times 7\), 64, Step-length 2 \\ \hline \multirow{3}{*}{Convolution layer 2} & \multirow{3}{*}{\(56\times 56\)} & \(3\times 3\), Max pooling, Step-length 2 \\ \cline{3-3}  & & \(\begin{bmatrix}1\times 1,256\\ 3\times 3,256,C=32\\ 1\times 1,128\end{bmatrix}\times 3\) \\ \hline \multicolumn{3}{c}{The first auxiliary classifier} \\ \hline Convolution layer 3 & \(28\times 28\) & \(\begin{bmatrix}1\times 1,512\\ 3\times 3,512,C=32\\ 1\times 1,256\end{bmatrix}\times 3\) \\ \hline Convolution layer 4 & \(14\times 14\) & \(\begin{bmatrix}1\times 1,1024\\ 3\times 3,1024,C=32\\ 1\times 1,512\end{bmatrix}\times 9\) \\ \hline \multicolumn{3}{c}{The second auxiliary classifier} \\ \hline Convolution layer 5 & \(7\times 7\) & \(\begin{bmatrix}1\times 1,2048\\ 3\times 3,2048,C=32\\ 1\times 1,1024\end{bmatrix}\times 3\) \\ \hline \multicolumn{3}{c}{Convolutional pooling layer, 1000 neurons, Softmax classifier} \\ \hline \end{tabular}
\end{table}
Table 2: Improved ResNet-50 network architecture.  
In the channel attention module, the global average pooling and maximum pooling of the same input feature space are performed to obtain the spatial information of the feature map, and then the obtained feature space information is input into the multi-layer awareness mechanism module of the next layer for dimension reduction and dimension-increase processing. The weight of the two shared convolution layers in the multi-layer awareness network is shared. Then, the characteristics of the perceptual network output are added and then processed with the sigmoid activation function to obtain channel attention. The calculation formula is shown in Formula (4).  
\[Mc(F)=\varepsilon[MLP(F_{avg}^{c})+MLP(F_{\max}^{c})] \tag{4}\]  
Among them, \(Mc\) is the channel attention module calculation factor, \(\varepsilon\) is the sigmoid activation function, \(MLP\) is the multi-layer perceptron, and \(F\) represents the feature vector.  
Spatial attention features are complementary to channel attention and reflect the importance of input values in spatial dimensions. The calculation formula is shown in Formula (5). First, global average pooling and global maximum pooling of one channel dimension are performed on the feature map, then the two features are spliced, and finally the dimension is reduced to one by \(7\times 7\) convolution post-channel processing using the sigmoid function [32] to generate spatial attention feature maps.  
\[Ms(F)=\varepsilon\Big{\{}conv_{7\times 7}[unit(F_{avg}^{s},F_{\max}^{s})]\Big{\}} \tag{5}\]  
Among them, \(Ms\) is the space attention module calculation factor, \(\varepsilon\) is the sigmoid activation function, \(MLP\) is the multi-layer perceptron, \(F\) represents the feature vector, \(unit\) is the channel combination, and \(conv\) is the convolution operation.  
In order to facilitate the use of pre-trained models during the experiment, CBAM is not embedded in all convolutional residual blocks, but only acts after different convolutional layers.